Hi there! I recently started to learn C Language.
I managed to write program for getting sum and average score for english and spanish.
But the problem is that i'm keep getting "source.c has stopped working" error.
This is the program that i wrote
Code:
#include <stdio.h>
FILE *file;
void main(void)
{
int num[10], spa[10], eng[10], a, sum[10], avg[10];
char name[10];
printf("Stud # Name Spanish English Sum Average\n");
file = fopen("Data.txt", "r");
for (a = 0; a < 10; a++)
{
fscanf(file, "%d %s %d %d", &num[a], &name[a], &spa[a], &eng[a]);
sum[a] = spa[a] + eng[a];
avg[a] = sum[a] / 2;
printf("%d %s %d %d %d %d", num[a], name[a], spa[a], eng[a], sum[a], avg[a]);
}
fclose(file);
}
And this is the "Data. txt"
Code:
1111 Guy1 82 91
1112 Guy2 75 29
1113 Guy3 88 75
1114 Guy4 50 62
1115 Guy5 70 56
1116 Guy6 96 98
1117 Guy7 75 90
1118 Guy8 88 82
1119 Guy9 82 88
1120 Guy10 91 99
As far as i know, this program can open "data.txt" but can go further than that.
Thanks in advance!