QUOTE(starter @ 3 Dec, 2006 - 05:45 PM)

I have a problem with my homework.I couldn't parse my input file. The input file includes lines.I attach a simple input file.
There are spaces at the end of the lines. The lenght of the line is 110 characters. The problem is the spaces at the end of the lines. How can i parse the lines?
I used this parser but when the parse come to the end of the line it doesn't go next line.
void parse(char * line,char * tlist[])
{
* tlist = strtok(line, " ");
while(*tlist)
{
tlist++;
* tlist = strtok(NULL, " ");
}
}
Thanks...
are you reading the file line by line, e.g.
CODE
char line[120];
char *tlist[100]={0};
while (fgets(line, 120, in_file) != NULL) /* read line */
{
printf("%s", line); /* write line */
parse(line, tlist); /* get tokens */
for (i=0; tlist[i] != NULL; i++ ) /* print tokens */
printf( "token is \"%s\"\n", tlist[i] );
}
which should work - fgets() leaves the '\n' in line so it would be treated as a token is that the problem?
This post has been edited by horace: 3 Dec, 2006 - 11:58 AM