Help!!!!

This is a discussion on Help!!!! within the C Programming forums, part of the General Programming Boards category; Hi folks, big one this, any help greatly appreciated! Basically the program reads the input file and then outputs the ...

  1. #1
    JFK
    JFK is offline
    Registered User
    Join Date
    Oct 2001
    Posts
    15

    Question Help!!!!

    Hi folks, big one this, any help greatly appreciated!

    Basically the program reads the input file and then outputs the results (meant to be student data). The first digit represents the student group (between 1 and 5 - random order) and the second digit represents the number of attempts at the exam made. 99 represents the end of the file.

    Input file (ch7d.dat)
    1 0
    1 0
    1 1
    1 1
    1 2
    5 2
    5 2
    5 1
    4 2
    4 2
    4 0
    4 1
    2 2
    99

    Output to file called assess.dat:

    Student assessment attempt report

    Group 1
    None 2
    One 2
    Both 1
    Total 5

    Group 5
    Both 2
    One 1
    Total 3

    Group 4
    Both 2
    None 1
    One 1
    Total 4

    Group 2
    Both 1
    Total 1

    Program specification

    Const int end_marker = 99

    Open input and output files
    Read first group and assessments attempted
    Output heading line
    WHILE not at the end of the data
    Initialise group total = 0
    Store group as current group
    Output group heading
    WHILE still processing current group AND not at end of data
    Increment attempt total
    Initialise attempts total = 0
    WHILE still processing the current attempts AND still processing
    current group AND not at end of data
    Increment attempt total
    Read next group and assessments attempted
    IF current attempt is 2
    Output “Both”
    ELSE IF current attempt is 1
    Output “One”
    ELSE
    Output “None”
    Output attempt total
    Accumulate group total
    Output group total
    Close files

    My code so far is (pitiful - I know!):

    #include<stdio.h>

    main()

    {
    const int end_marker = 99;

    int first_group,
    assess_attempt,
    group_total,
    current_group;

    FILE *assess = fopen("assess.dat", "w");
    FILE *ch7d = fopen("ch7d.dat", "r");

    fscanf(ch7d, "%d %d", &first_group, &assess_attempt);
    fprintf(assess, "Student Assessment Attempt Report\n\n");

    while ((first_group && assess_attempt) != end_marker)
    {
    group_total = 0;
    current_group = first_group;
    fprintf(assess, "Group")
    }

    fclose(assess);
    fclose(ch7d);

    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,535
    Code:
    char buff[BUFSIZ];
    while ( fgets( buff, BUFSIZ, ch7d ) != NULL ) {
      int group, attempts;
      sscanf( buff, "%d %d", &group, &attempts );
      if ( group == 99 ) break;
      // over to you
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21