I have used strtok to tokenize my input file and I need a linked list based on the output I got in the follwing format.
String:value-Next --> String:value-Next
I have the strings and values after I tokenized my file.
Here is my code:
FILE *pfi;
main(int argc, char* argv[])
{
char string[1000], delim[] = " \n";
char *p;
if(argc<2)
{
printf("entering format is wrong. compile program using gcc digraph.c and then enter it as ./a.out input.txt");
}
else if(argc == 2)
{
pfi=fopen(argv[1],"r");
}
if(!pfi)
return 1;
while(fgets( string, sizeof(string)-1, pfi) != NULL)
{
p = string;
p = strtok( string, delim );
while( p != NULL )
{
if (sscanf(p, "( %s ",p)) printf("(\n");
printf("%s\n", p);
p = strtok( NULL, delim );
}
} fclose(pfi);
return 0;
}
The input file is in format:
A 20
B 30
C 40
Output is:
A
20
B
30
C
40
Please help me to create a linked list of format String:value-Next --> String:value-Next.
1 Answer