Here's something
Code:
#include <stdio.h>
// This uses a static buffer - you must use the result before
// calling this function again, otherwise the first result will be lost
// it also doesn't handle || as being an empty field
char *gettok( FILE *fp ) {
static char buff[200];
int i = 0;
int ch;
while ( (ch=fgetc(fp)) != EOF ) {
if ( ch == '|' ) {
break; // end of field marker
} else {
buff[i++] = ch; // save the char
buff[i] = '\0'; // and keep the buffer \0 terminated
}
}
if ( i == 0 ) {
return NULL; // first read was EOF (or |EOF)
} else {
return buff;
}
}
int main ( ) {
FILE *fp = fopen( "member.txt", "r" );
char *c;
while ( (c=gettok(fp)) != NULL ) {
printf( "Found '%s'\n", c );
}
fclose( fp );
return 0;
}
Make sure it does all you want it to do, before burying it inside some larger program.