struct recordNode {
char district[50];
int employees;
int employers;
int students;
int retried;
int others;
struct recordNode* left;
struct recordNode* right;
};
FILE *getFile (char filename[]) {
struct recordNode* node;
FILE* fpin;
FILE* fpout;
char line_buffer[lineSize]; /* BUFSIZ is defined if you include stdio.h */
int counter = 0;
filename = "testData.txt";
//file validation
fpin=fopen("testData.txt", "r");
if (fpin == NULL ) exit(0);
counter = 0;
while (fgets(line_buffer, sizeof(line_buffer), fpin)) { /* same as while (feof(in) != 0) */
counter++;
if (counter != 0) {
//Central & Western - Chung Wan,7576,1042,2156,1875,3154 (sample data)
sscanf(line_buffer, "%s,%d,%d,%d,%d", node->district, node->employees, node->students, node->retried, node->others);
printf("%s", node->district); **//error**
}
getchar();
}
getchar();
return fpout;
}
i got a error when i compile, what’s wrong with my code? There is a error message
Project Project1.exe raised exception class EAccessViolation with Message ……………….. (borland C++)
Your problem (or at least one of them) is here:
all except the first of those parameters should be pointers:
Also, this:
shouldn’t be there at all – the name of the file to read is passed in as a parameter to the function.
And lastly, this:
should be:
and you need to change things like
node->districttonode.district. This is tiring work – perhaps you could put a bit more effort into chasing these things down before posting here. You will learn much more that way.