Home › Forums › C Programming › Help – file reading › Re: Re: Help – file reading
March 23, 2009 at 10:19 am
#3534
Ernesto0751
Participant
now my program able to read the file by adding some code given by you, but i couldnt understand how it actually run..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #include <stdio.h><br /> <br /> <br /> void main (void)<br /> {<br /> char matrix[20][200], line[100][100];<br /> int i, j, x, no[20], quiz_1[20], quiz_2[20], quiz_3[20], project[20], midT[20], final[20];<br /> FILE *infile;<br /> <br /> infile = fopen("studentsmark.txt","r");<br /> <br /> x=0;<br /> while (fgets(line,100,infile)!=NULL)<br /> {<br /> <br /> x++;<br /> if(x==1)<br /> {<br /> <br /> }<br /> <br /> else{<br /> i=0;<br /> while( fscanf(infile,"%d %s %d %d %d %d %d %d",&no<i>,matrix</i><i>, &quiz_1</i><i>, &quiz_2</i><i>, &quiz_3</i><i>, &project</i><i>, &midT</i><i>, &final</i><i>) !=EOF)<br /> <br /> <br /> <br /> printf("%d %s %d %d %d %d %d %dn",no</i><i>, matrix</i><i>, quiz_1</i><i>, quiz_2</i><i>, quiz_3</i><i>, project</i><i>, midT</i><i>, final</i><i>);<br /> i++;<br /> <br /> <br /> <br /> <br /> }<br /> <br /> }<br /> fclose(infile);<br /> }</i> |
this is my actual input file
1 2 3 4 5 6 7 8 9 10 11 12 | 123401234567890123456789012345678901234567890123456789012345678901234567890123456789<br /> No Matrix quiz1(5%) quiz1(5%) quiz1(5%) Proj(25%) MidT(20%) Final(40%)<br /> 1 BK20008 4 3 5 18 18 36<br /> 2 BK20002 5 5 4 10 8 30<br /> 3 BK20003 3 4 5 18 10 35<br /> 4 BK20006 4 3 4 20 14 36<br /> 5 BK20005 5 4 3 13 17 28<br /> 6 BK20004 2 5 2 4 16 10<br /> 7 BK20007 3 4 4 21 14 32<br /> 8 BK20001 4 3 5 11 15 31<br /> 9 BK20009 3 2 4 10 10 20<br /> 10 BK20010 4 3 3 23 18 22 |
there is a line of number in the input file.can you explain to me? thanks!