Maybe something like this? Here are the contents of my "file.txt":
Code:
this , is , an , example
this,is,another,example
and , this,is, also an, example ,
this isn't, (just kidding!)
The code:
Code:
#include <stdio.h>
int main(void)
{
const char filename[] = "file.txt";
FILE *file = fopen(filename, "r");
if(file != NULL)
{
char buffer[BUFSIZ], fmt[32];
int i = 0;
sprintf(fmt, "%%%lu[^,]%%*c", (long unsigned)sizeof(buffer));
while(fscanf(file, fmt, buffer) == 1)
{
printf("%3d \"%s\"\n", i++, buffer);
}
fclose(file); /* [edit]I missed this, CodeMaster gets the credit[/edit] */
}
return 0;
}
My output:
Code:
0 "this "
1 " is "
2 " an "
3 " example
this"
4 "is"
5 "another"
6 "example
and "
7 " this"
8 "is"
9 " also an"
10 " example "
11 "
this isn't"
12 " (just kidding!)
"
Note the newlines that remain in the output because the comma is the only delimiter.