My program has runtime error and I do not know what is the problem, below are my text file followed by my coding:
student.txt:
10wad00800|kong meng|3.80
10wad00900|jen sen|3.20
Code:
#include<stdio.h>
void main()
{
FILE *myfile;
char data1[20],data2[20],data3[5];
int i;
myfile=fopen("student.txt","r");
if(!myfile)
printf("file not found\n");
else
{
printf("Student ID\t\tName\t\tCGPa\n"
"=============\t\t====\t\t====\n");
while(!feof(myfile))
{
fscanf(myfile,"%[^|]|%[^|]|%[^\n]",data1[i],data2[i],data3[i]);
printf("%s\t\t%s\t\t%s\n",data1[i],data2[i],data3[i]);
i++;
}
}
fclose(myfile);
}