Hi. Here's the code:
Code:
/* Jack White 090455775
EE Programming Fundamentals Lab 9
Question 3
*/
#include <stdio.h>
struct town_info {
char name[59]; /*The longest place name in Britain is 58 characters long*/
int d_from_lon;
};
int main(void) {
struct town_info town[5];
int counter;
for (counter=0; counter < 5; counter ++) {
printf("Enter a town: ");
gets(town[counter].name);
printf("Enter its distance from London (in miles): ");
scanf(" %d", &town[counter].d_from_lon);
}
printf("\nThe following towns are less than 100 miles from London: \n");
for (counter=0; counter < 5; counter ++) {
if (town[counter].d_from_lon < 100) {
puts(town[counter].name);
}
}
return 0;
}
/*End of programme*/
When it prints out the names at the end, the first character is missing from the first town. I already know about the problem with gets, btw, but I don't want to upset my lecturer. It doesn't work any better with fgets, or indeed scanf.
Any ideas?
Thanks.