(#gold) (#silver) (#bronze) (country name)
example
23 21 22 Programming Land
12 4 6 Bosnia
this is my code, I am not sure but I think I have an infinite loop, it compiles but when I run it on Putty it just doesn't do anything, doesn't close either. It creates the output file, and i am relatively certain it is reading the input file, but there is nothing being written in the output file.
// Olajubu Folaranmi Section 0103 Week 7
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int gold, silver, bronze, i, k, EOF_reached;
char country[30];
char c;
//declare files
FILE *data, *output;
// open files and check for errors
data = fopen(argv[1], "r");
if (data == NULL)
{ printf("File %s cannot open!\n", argv[1]);
exit(0);
}
output = fopen(argv[2], "w");
while (fscanf(data, "%d %d %d", &gold, &silver, &bronze) != EOF){
if (gold > 0 || silver > 0 || bronze > 0){
i = 0;
while(i <= 31){
EOF_reached = fscanf(data, "%c", &c);
if(c == '\n' || EOF_reached == EOF){
country[i] = '\0';
break;
}
else{
country[i] = c;
}
i++;
}
k=0;
while (k<=i){
fprintf(output, "%c", country[k]);
k++;
}
}
}
fclose(data);
fclose(output);
return 0;
}

New Topic/Question
Reply



MultiQuote






|