0
Storing value from txt file (C)
I'm working on a code that has to take a value from a txt file, i have to read it with fgets and the txt file is set like this: ITEM: 22 i tried doing something like char line[50]; fgets(line,50,/*nameoffile*/); if(strstr(line,"ITEM: ")){ /*code*/} but then i dont know what to do in the if statement. I'm working on windows,not on code playground.
3 Answers
+ 1
do you want access 22?
if yes
then you should try this...
char *ptr=strstr(line,"ITEM: ") ;
if(ptr) {
print(ptr+6);
}
/*
strstr = Returns pointer to first occurrence of "ITEM: " in line.
i have stored in a pointer.
In the print statement i have written ptr+6. i set the pointer position to the 6 place from its original position.
and i have choose 6 because of length of "ITEM: " is 6.
*/
+ 1
đđđ
0
You saved my day