• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Parsing data in C

darkessenz21

Senior member
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.
 
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.
 
Back
Top