• Ernesto0751
    Member
    Post count: 5
    #2182 |

    hi,

    can someone give me the idea on how to read the following file (student’s mark text file) using array and then print it out, how would be the design of the code?

    No Matrix quiz1(5%) quiz1(5%) quiz1(5%) Proj(25%) MidT
    1 BK20008 4 3 5 18 18
    2 BK20002 5 5 4 10 8
    3 BK20003 3 4 5 18 10
    4 BK20006 4 3 4 20 14
    5 BK20005 5 4 3 13 17
    6 BK20004 2 5 2 4 16
    7 BK20007 3 4 4 21 14
    8 BK20001 4 3 5 11 15
    9 BK20009 3 2 4 10 10
    10 BK20010 4 3 3 23 18

    i’m not asking for code because this is my project. After reading the file, the program have to calculate the grade and sort them, but first i have to know how to read this file

    any kindly help i will be very appreciate!
    thanks in advance

  • JonathaThurston
    Member
    Post count: 8
    #3529 |

    Are you using C or C++? If its C the following can help.

  • Ernesto0751
    Member
    Post count: 5
    #3530 |

    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…

  • Ernesto0751
    Member
    Post count: 5
    #3531 |

    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…

  • msaqib
    Participant
    Post count: 57
    #3532 |

    Use fgets() function to read the file line by line and then split the string and store all the values in variables.

  • Ernesto0751
    Member
    Post count: 5
    #3533 |

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

  • Ernesto0751
    Member
    Post count: 5
    #3534 |

    now my program able to read the file by adding some code given by you, but i couldnt understand how it actually run..

    this is my actual input file

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

  • msaqib
    Participant
    Post count: 57
    #3535 |

    The code

    reads the file and function fgets() reads the file line by line. So when the program reads first line, it skips the first line of records which is
    No Matrix quiz1(5%) quiz1(5%) quiz1(5%) Proj(25%) MidT(20%) Final(40%)
    and is done by this code:

    And you read all the marks and data in else part of the program.

You must be logged in to reply to this topic.