Forum Replies Created

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • in reply to: Help – file reading #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..

    #include 


    void main (void)
    {
    char matrix[20][200], line[100][100];
    int i, j, x, no[20], quiz_1[20], quiz_2[20], quiz_3[20], project[20], midT[20], final[20];
    FILE *infile;

    infile = fopen("studentsmark.txt","r");

    x=0;
    while (fgets(line,100,infile)!=NULL)
    {

    x++;
    if(x==1)
    {

    }

    else{
    i=0;
    while( fscanf(infile,"%d %s %d %d %d %d %d %d",&no,matrix, &quiz_1, &quiz_2, &quiz_3, &project, &midT, &final) !=EOF)



    printf("%d %s %d %d %d %d %d %dn",no
    , matrix, quiz_1, quiz_2, quiz_3, project, midT, final);
    i++;




    }

    }
    fclose(infile);
    }

    this is my actual input file

    123401234567890123456789012345678901234567890123456789012345678901234567890123456789
    No Matrix quiz1(5%) quiz1(5%) quiz1(5%) Proj(25%) MidT(20%) Final(40%)
    1 BK20008 4 3 5 18 18 36
    2 BK20002 5 5 4 10 8 30
    3 BK20003 3 4 5 18 10 35
    4 BK20006 4 3 4 20 14 36
    5 BK20005 5 4 3 13 17 28
    6 BK20004 2 5 2 4 16 10
    7 BK20007 3 4 4 21 14 32
    8 BK20001 4 3 5 11 15 31
    9 BK20009 3 2 4 10 10 20
    10 BK20010 4 3 3 23 18 22

    there is a line of number in the input file.can you explain to me? thanks!

    in reply to: Help – file reading #3533
    Ernesto0751
    Participant

    thanks! i hav been thinking the whole day for this. I will try working on it !

    in reply to: Help – file reading #3531
    Ernesto0751
    Participant
    int main ()
    {
    char matrix[20][200];
    int i, j, no[20], quiz_1[20], quiz_2[20], quiz_3[20], project[20], midT[20];
    FILE *infile;

    infile = fopen("studentsmark.txt","r");

    i=0;

    while( fscanf(infile,"%d %s %d %d %d %d %d",&no, matrix, &quiz_1, &quiz_2, &quiz_3, &project, &midT) !=EOF) i++;



    for(j=0;j {
    printf("%d %s %d %d %d %d %dn",no[j], matrix[j], quiz_1[j], quiz_2[j], quiz_3[j], project[j], midT[j]);
    }

    fclose(infile);
    }#include


    int main ()
    {
    char matrix[20][200];
    int i, j, no[20], quiz_1[20], quiz_2[20], quiz_3[20], project[20], midT[20];
    FILE *infile;

    infile = fopen("studentsmark.txt","r");

    i=0;

    while( fscanf(infile,"%d %s %d %d %d %d %d",&no
    , matrix, &quiz_1, &quiz_2, &quiz_3, &project, &midT) !=EOF) i++;



    for(j=0;j {
    printf("%d %s %d %d %d %d %dn",no[j], matrix[j], quiz_1[j], quiz_2[j], quiz_3[j], project[j], midT[j]);
    }

    fclose(infile);
    }

    but i am unable to read tis line
    No Matrix quiz1(5%) quiz1(5%) quiz1(5%) Proj(25%) MidT(20%)

    what should i add to make the program read it and ignore it so it can read on the real data i need, i really have no idea…

    in reply to: Help – file reading #3530
    Ernesto0751
    Participant
    int main ()
    {
    char matrix[20][200];
    int i, j, no[20], quiz_1[20], quiz_2[20], quiz_3[20], project[20], midT[20];
    FILE *infile;

    infile = fopen("studentsmark.txt","r");

    i=0;

    while( fscanf(infile,"%d %s %d %d %d %d %d",&no, matrix, &quiz_1, &quiz_2, &quiz_3, &project, &midT) !=EOF) i++;



    for(j=0;j {
    printf("%d %s %d %d %d %d %dn",no[j], matrix[j], quiz_1[j], quiz_2[j], quiz_3[j], project[j], midT[j]);
    }

    fclose(infile);
    }#include


    int main ()
    {
    char matrix[20][200];
    int i, j, no[20], quiz_1[20], quiz_2[20], quiz_3[20], project[20], midT[20];
    FILE *infile;

    infile = fopen("studentsmark.txt","r");

    i=0;

    while( fscanf(infile,"%d %s %d %d %d %d %d",&no
    , matrix, &quiz_1, &quiz_2, &quiz_3, &project, &midT) !=EOF) i++;



    for(j=0;j {
    printf("%d %s %d %d %d %d %dn",no[j], matrix[j], quiz_1[j], quiz_2[j], quiz_3[j], project[j], midT[j]);
    }

    fclose(infile);
    }

    but i am unable to read tis line
    No Matrix quiz1(5%) quiz1(5%) quiz1(5%) Proj(25%) MidT(20%)

    what should i add to make the program read it and ignore it so it can read on the real data i need, i really have no idea…

Viewing 4 posts - 1 through 4 (of 4 total)