Hi,
After I posted to the question, I have do some searching on delimiter.
Try to modify the program, it almost solved the problem.
Only the number
256 problem remain unresolved.
Can someone please help.
Thanks.
Henry
Code:
#include <stdio.h>
int main()
{
FILE *fp=fopen("e:\\text.txt", "r");
char city[256],country[256];
int pop;
while(!feof(fp))
{
fscanf(fp, "%[^%s%s%d]", city,country, &pop);
printf("%s%s%d",city,country, pop);
}
fclose(fp);
getchar();
return 0;
}
What I want to do is to
1. Get city name from user
2. If is in file, print its population.
If is do able, do I have to
...............1. Copy the population input to tmp[]
...............2. Clear out the country and population input
...............3. Compare char by char to see the input city name is in the file before
, in each line.
...............4. If found
.......................4.1 put back tmp[] into buffer
.......................
assume
..................................(A) country[] removed from buffer &
..................................(B) the buffer now contain only two input info, (A) city name[] (B) populati.
......................4.2 Print the cityname and its population.