I'm having trouble with my readfile
method.
I can't print out the number values in my text file, but my name is fine.
This is all that is inside my text file:
Bob
10
12.00
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "iofunctions.h"
int readfile( struct account accarray[], int* numcust, char filename[])
{
/* variables */
FILE *inputFile;
char line[25];
char spaceEater[25];
char name[25]={"\0"};
int accountNum;
float money ;
inputFile = fopen("People_Info.txt", "r");
if(inputFile == NULL)
{
fprintf(stderr, "Sorry, I cannot open this file. Also it's empty.\n");
exit(1);
}
/*outer loop is to check if file is not null*/
while(!feof(inputFile))
{
/*while file has something*/
while(fscanf(inputFile,"%s %d %f", name,&accountNum,&money))
{
accarray->accountno = accountNum;
accarray->balance = money;
printf("name = %s number = %d balance = %f\n", name, &accountNum, &money);
}
}
fclose(inputFile);
return 0;
}
Also this is my struct:
struct account
{
char name[25];
int accountno;
float balance;
};