I want to sub-function the reading and printing data.
But it says data corrupted.
Sorry for my poor english.
Example of inputfile.txt
Michael
000000
m
michael@abc.com
75
82
90
#include <stdio.h>
#include <string.h>
void readData();
void printData();
struct student
{
char studName;
int studID;
char sex;
char email;
int mathsScore;
int englishScore;
int scienceScore;
};
int main(void)
{
struct student data[20];
readData();
printData();
return 0;
}
void readData()
{
struct student data[20];
int i=0;
FILE* input;
input=fopen("inputfile.txt", "r");
while((fscanf(input,"%s %d %c %s %d %d %d", &data[i].studName,&data[i].studID,&data[i].sex,&data[i].email,&data[i].mathsScore,&data[i].englishScore,&data[i].scienceScore))==7)
{
i++;
}
}
void printData()
{
readData();
struct student data[20];
for(int i=0;i<20;i++)
{
printf("%d.%s\n%.6d\n%c\n%s\n%d\n%d\n%d\n\n",i+1, data[i].studName,data[i].studID,data[i].sex,data[i].email,data[i].mathsScore,data[i].englishScore,data[i].scienceScore);
}
}