I'm done writing a code but can't figured out the solution for error. I think it's quite simple fix.
I have 3 files
grades.txt // contains 8 grades
grades.h // structure
grades.c // main
Here are the description of the program is asking
- Accepting two arguments, 1 for filename grades.txt, and 1 for user ID (ex.123)
- Display the grades and those average, until I have all 8 grades or met the negative grades
- Convert user ID into a number uid
- Read the structure starting at offset (uid*sizeof(struct GR))
grades.h
#ifndef GRADE
#define GRADE
struct GR {
float gr[8];
};
#endif
grades.c
#include <stdio.h>
#include "grades.h"
int main(int argc, char *argv[]) {
struct GR *grades = melloc(sizeof(struct GR));
FILE *file = fopen(argv[1], "rb");
// convert character uid into integer uid
char *chUid = argv[2];
int uid = 0;
int len = strlen(chUid);
for (int i = 0; i < len; i++) {
uid = uid * 10 + (chUid[i] - '0');
}
printf("Converted uid: %d \n", uid);
fread(grades, uid * sizeof(struct GR), 1, file);
float total = 0, avg = 0;
int i = 0;
while (i < 9 && grades->gr[i] > 0) {
printf("%d\n", grades->gr[i]);
total += grades->gr[i];
i++;
}
printf("Average: %d \n", total / i);
return 0;
}
my error msg are
error LNK2019: unresolved external symbol _melloc referenced in function _main
error LNK1120: 1 unresolved externals
----update------
I added header and changed the typo from melloc and malloc, the error is gone but I'm stuck on fread method.. struct is not having any value