I am parsing a file for particular keyword matching by C program, here is my sample code...
#include <stdio.h>
int main() {
FILE *infile = fopen("Somefile.txt", "r");
char buffer[256];
char value[128];
while (fgets(buffer, sizeof(buffer), infile))
if (1 == sscanf(buffer, " x = %s", value))
printf("Value = %s\n", value);
return 0;
}
Somefile.txt
some junk
#a comment
a = 1 ; a couple other variables.
b = 2
x = 3
x = 4
x=5
x = Hi hello
Output:
Value = 3
Value = 4
Value = 5
Value = Hi
Problem : when x contain the value like "Hi Hello", then it just parsing "Hi" only, I want to parse whole value of x without loosing space.
please suggest me solution for it.
Thanks.