MLUG: Re: [MLUG] String manipulation in C
Re: [MLUG] String manipulation in C
Email address obfuscation in effect -- please click here to turn it off.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


On Sun, 1 Jul 2007, Mark Rages wrote:

On 7/1/07, Jack Smith <EMAIL:PROTECTED> wrote:
The matches will need to be put in a MATLAB data frame first and then a
MySQL database later. Outputting data in columns would work as I could
read the columns in later to make the data frame.

I know that grep will find the expression as many times as it appears in
the string searched. But I need it to find how many characters the start
of the match is from the start of the string. The best that I see can
come from grep is number of letters that the first character in the line
the match is in is from the start (the byte offset.) But I need the
actual distance from start -> match.


Jack


OK, if you wanna try C:

#include <string.h>

void print_offset_matches(char *needle, char *haystack) {
char *begin=haystack;

while (haystack=strstr(haystack,needle))
  printf("%d\n",haystack-begin);
}

Or it might need to be

  while (haystack=strstr(haystack,needle)) {
    printf("%d\n",haystack-begin);
    haystack++;
  }
}

_______________________________________________
members mailing list
EMAIL:PROTECTED
http://mlug.missouri.edu/mailman/listinfo/members