1. 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
WHILE not at the end of the data
Initialise group total = 0
Store group as current group
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. 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
}```

Popular pages Recent additions