-
input file
I'm trying to get data from an input file then manipulate it but all i want is to get the data in and display it so i know that I have got it in to the program. I'm reading the data from the attached filr and here's my code so far...
{
char FileName[100], Data[100];
FILE *Input, *Output;
puts("Please enter a file name: ");
gets(FileName);
Input=fopen(FileName, "r");
if(Input==NULL)
{
printf("Could not open the file\n");
exit(0);
}
for(i=0;i<NO_OF_GYMNASTS;i++)
{
fgets(Competitors[i].Name, 50, Input);
fgets(Competitors[i].Country, 50, Input);
fscanf(Input, "%d", &Competitors[i].Age);
for(count=0;count<NO_OF_JUDGES;count++);
{
fscanf(Input, "%f\n", &Competitors[i].JudgesScores[NO_OF_JUDGES]);
}
}
fclose(Input);
for(i=0;i<NO_OF_GYMNASTS;i++)
{
puts(Competitors[i].Name);
puts(Competitors[i].Country);
fprintf(Input, "%2d", Competitors[i].Age);
for(count=0;count<NO_OF_JUDGES;count++);
{
fprintf(Input, "%f", &Competitors[i].JudgesScores[NO_OF_JUDGES]);
}
}
puts("Please enter an output filename: ");
gets(FileName);
Output=fopen(FileName, "w");
if(Output==NULL)
{
printf("Could not open the output file\n");
exit(0);
}
for(i=0;i<NO_OF_GYMNASTS;i++)
{
fputs(Competitors[i].Name, Output);
}
fclose(Output);
}
***THANK YOU FOR ANY HELP!!!***
-
remove the ; from the for loops first. Then try again
for(count=0;count<NO_OF_JUDGES;count++); <-----
{
fscanf(Input, "%f\n", &Competitors[i].JudgesScores[NO_OF_JUDGES]);
}
for(count=0;count<NO_OF_JUDGES;count++); <------
{
fprintf(Input, "%f", &Competitors[i].JudgesScores[NO_OF_JUDGES]);
}
-
Input file
I have removed the ";'s" from the end of the loops but now I am unable to get ANY of the ages or scores into the file. AAARGH!!!
Someone please help!!!
{
Gymnast Competitors[NO_OF_GYMNASTS];
int i;
int count;
char FileName[100], Data[100];
FILE *Input, *Output;
puts("Please enter a file name: ");
gets(FileName);
Input=fopen(FileName, "r");
if(Input==NULL)
{
printf("Could not open the file\n");
exit(0);
}
for(i=0;i<NO_OF_GYMNASTS;i++)
{
fgets(Competitors[i].Name, 50, Input);
fgets(Competitors[i].Country, 50, Input);
fscanf(Input, "%d\n", &(Competitors[i].Age));
for(count=0;count<NO_OF_JUDGES;count++)
{
fscanf(Input, "%f\n", &Competitors[i].JudgesScores[NO_OF_JUDGES]);
}
}
fclose(Input);
for(i=0;i<NO_OF_GYMNASTS;i++)
{
puts(Competitors[i].Name);
puts(Competitors[i].Country);
fprintf(Input, "%d\n", Competitors[i].Age);
for(count=0;count<NO_OF_JUDGES;count++)
{
fprintf(Input, "%f\n", &Competitors[i].JudgesScores[NO_OF_JUDGES]);
}
}
puts("Please enter an output filename: ");
gets(FileName);
Output=fopen(FileName, "w");
if(Output==NULL)
{
printf("Could not open the output file\n");
exit(0);
}
for(i=0;i<NO_OF_GYMNASTS;i++)
{
fputs(Competitors[i].Name, Output);
}
fclose(Output);
}
-
for(count=0;count<NO_OF_JUDGES;count++)
{
fprintf(Input, "%f\n", &Competitors[i].JudgesScores[NO_OF_JUDGES]);
}
Remove the & before Competitors[i].JudgesScore .....
-
:) You know what's bothering me is that you are apparently using structures but haven't declared any. :confused: