This is the Algorithm:
- Open the file.
- Read a string from the file.
- Compare the string.
- If the string matches, get the number/s after '=', then exit the loop.
- Check the end of the file.
- If it's not yet the end of the file, go back to step 2.
- If the end of the file is met exit the loop, and go to step 5.
- The string is not in the file.
This is the program i made:
FILE *fp = fopen("Converter.txt", "r");
while( fgets(line, sizeof(line), fp) != NULL ){
if(strcmp(line,a)){
printf("There is such file");
sscanf(line,"%*[^=]=%f", &num);
printf("\n\n%.2f",num);
}else{
printf("NULL\n");
continue;
}break;
}
The problem is it only scan the first line and it doesn't scan the number beside the string that it compares.
Thanks.
Aucun commentaire:
Enregistrer un commentaire