Hi, I seem to be having trouble doing this.
I have a text file containing: 173 44 84 0 25
and when I read in the numbers and try to spit them back out, I get: -1.00 -1.00 -1.00 -1.00 -1.00
Here's the code.
int main()
{
/* define local variables */
FILE *firstfile;
float NumArray[5];
int count;
/* begin statements */
/* opens the file A:\Five_Num.txt */
firstfile = fopen("A:\Five_Num.txt", "r"
/* reads in numbers from file */
for(count = 0; count < 5; count++)
NumArray[count] = fscanf(firstfile, "%f", &NumArray[count]);
for(count = 0; count < 5; count++)
printf("%.2f", NumArray[count]);
fflush(stdin);
getchar();
return(0);
}
So what's my problem?
I have a text file containing: 173 44 84 0 25
and when I read in the numbers and try to spit them back out, I get: -1.00 -1.00 -1.00 -1.00 -1.00
Here's the code.
int main()
{
/* define local variables */
FILE *firstfile;
float NumArray[5];
int count;
/* begin statements */
/* opens the file A:\Five_Num.txt */
firstfile = fopen("A:\Five_Num.txt", "r"
/* reads in numbers from file */
for(count = 0; count < 5; count++)
NumArray[count] = fscanf(firstfile, "%f", &NumArray[count]);
for(count = 0; count < 5; count++)
printf("%.2f", NumArray[count]);
fflush(stdin);
getchar();
return(0);
}
So what's my problem?