Parsing data in C

darkessenz21

Senior member
Oct 22, 2003
204
0
0
INPUT FILE

String p c d f e b p s
String c c 3 d 4 f j l





I am trying to parse this file in C


Here is the basic of my code

while(fscanf(fin, "%s", buffer)!=EOF)
{
if(strcmp(buffer, "String")==0)
{
while(strcmp(buffer, "\n"){
fscanf(fin, "%s", buffer)
createNode("buffer"); // Creates a node using the buffer as the name.

}
}
}


I am having a hard getting the input to recognize the newline character, and for it to stop at end of the line.
 

YaKuZa

Senior member
Aug 26, 2000
995
0
0
I'm having trouble understanding what you want parsed.

Can you give an example?

Sample output?
 

Vadatajs

Diamond Member
Aug 28, 2001
3,475
0
0
Your program loops until EOF. Have you tried getline() and strtok() ? (man getline, man strtok). Getline reads a line of input and strtok breaks up the string into tokens separated by whitespace (or any other character for that matter). Check out the man pages for details.