I have an issue with my homework where part of it requires scanning and reading some specific input. The related C code is:
typedef struct Train {
int train_number;
int priority; // 0 is low priority, 1 is high priority
int direction; // 0 is Westbound, 1 is Eastbound
float loading_time;
float crossing_time;
int loaded;
} Train;
#define MAX_TRAIN_COUNT 777
Train station[MAX_TRAIN_COUNT];
int main(int argc, char* argv[]) {
//read the input file
FILE *input;
char c;
int train_count = 0;
input = fopen(argv[1], "r");
while((c = getc(input)) != EOF) {
if(c == '\n')
train_count++;
}
int i;
for (i = 0; i < train_count; i++) {
char dir;
int load, cross;
fscanf(input, "%c %d %d\n", &dir, &load, &cross);
printf("%c %d %d\n", dir, load, cross);
}
fclose(input);
The input is 3 rows consisting of one char and two integers separated by spaces.
e 10 6
W 6 7
E 3 10
The output I get is:
4195728 0
Where there is a space before the 4195728. I cannot seem to find a solution to fix this.
What seems to be the problem?