I am trying to read in a file, find the string \"myprop\" and after \"myprop\" will be an \"=\" sign then a number. I need to print out just that number as a string, getting rid
You can add sscanf
in the moment when you find the mypop
string in the file. Add the following line in your while loop:
sscanf(buf,"%*[^=]= %[^\n]",value);
"%*[^=]"
: This means that scanf capte all characters befor the =
and ignore it
" %[^\n]"
: This means that you are capting all characters after the =
till the end of your buffer string (even the space characters). only the space characters in the beggining of the value string will not capted
add it in this way
while(fgets(buffer, 100, fp) != NULL)
{
if((strstr(buffer, propkey)) != NULL)
{
printf("Myprop found on line: %d\n", line_num);
printf("\n%s\n", buffer);
sscanf(buf,"%*[^=]= %[^\n]",value);
printf("\nvalue is %s\n", value);
break;
}
line_num++;
}