hello, doing an assignment for school and have the program written but it doesn't seem to do what it's supposed to. so far i have...
#include <stdio.h>
#include <math.h>
#define N 30
void readmarks (FILE* fin, int* id, float* mark, int* n);
float changemarks(int* student, int* id, float* mark, float* newmark, int n);
void writemarks(FILE* fout, int* id, float* mark, int* n);
int main(void){
int id[N];
float mark[N];
int student;
FILE*fin = fopen("marks.txt", "r");
FILE*fout = fopen("marksout.txt", "w");
float* newmark;
int value;
int n;
readmarks(fin, id, mark, &n);
while(1){
printf("enter an id and a new mark:");
scanf("%d %f", &student, &newmark);
if (student == 0){
break;
}
else{
changemarks(&student, id, mark, newmark, n);
}
value = changemarks(&student, id, mark, newmark, n);
if (value == 0){
printf("That student is not in the marks list\n");
}
}
writemarks(fout, id, mark, &n);
return 0;
}
void readmarks(FILE* fin, int* id, float* mark, int* n){
int a = 0;
while(fscanf(fin, "%d %f", &id[a], &mark[a]) !=EOF){
a++;
}
*n = a;
}
float changemarks(int* student, int* id, float* mark, float* newmark, int n){
int i;
for(i=0; i<n; i++){
if (id[i] == *student){
*newmark = mark[i];
return 1;
}
else{
return 0;
}
}
}
void writemarks(FILE*fout, int* id, float* mark, int* n){
fprintf(fout, "%d %10.2f\n", &id, &mark);
}
when i read from the file indicated, it doesn't detect the first value. here is what the file contains:
1004 85
2315 65
1930 78
2000 69
2002 77
2100 87
2929 64
1345 60
it merely says "enter a new value etc etc" and then says value cannot be found. any ideas? I'm new to arrays and pointers fyi. thanks for any help!