I am writing a code for a weather database, but when I go to print out the city and temperatures my first line is off by 1 character, and I cannot figure out why. One thing I did notice was that when i print for example printf("%20s", city); only the first city is being modified.
This is for a intro to C-Programming and they have not learned much about strings yet, which is why I read in character by character.
Here is the snippet of code I am referring to;
while(TRUE) {
for(
i=0;
fscanf(input,"%c", &c)!=EOF && c!='#';
i++)
{ //i.e. city#..
city[i]=c;
}
if(c=='#') {
city[i] = '\0'; //Next line scans in the weather for the days of the week
fscanf(input, " (%f, %f), (%d, %d), (%d, %d), (%d, %d), (%d, %d), (%d, %d), (%d, %d), (%d, %d)",&h_avg, &l_avg,&s1,&s2,&m1,&m2,&t1,&t2,&w1,&w2,&th1,&th2,&f1,&f2,&sa1,&sa2);
printf("%20s %d %d", city, s1,s2);
} else {
printf("\n");
break;
} //Break infinite loop because for loop broke from EOF
}
Sample output:
Baltimore 75 60
Miami 20 10
Washington D.C. 75 50
New York 75 50
only Baltimore is being right aligned. Any help is appreciated.