int main(int argc, char* argv) {
struct student_record_node *head;
char *filename = argv[1];
printf("%s",filename);
parseFile(filename,&head);
return (0);
}
struct student_record_node* student_record_allocate()
{
struct student_record_node *newNode;
newNode = malloc(sizeof (struct student_record_node));
return newNode;
}
void parseFile(char *filename, struct student_record_node**head)
{
FILE *fp=NULL;
char fname[21], flast[21];
int id,age;
int ret;
/*creates a POINTER to "filename"*/
fp = fopen(filename, "r+");
if (fp== NULL) {
printf("No such file\n");
exit(1);
}
printf("%s",fp->_tmpfname);
while (fp) {
struct student_record_node *new_student;
new_student = student_record_allocate();
fscanf(fp,"%s %s %d %d",new_student->record_->first_name_ , new_student->record_->last_name_,new_student->record_->student_id_, new_studen t->record_->student_age_);
new_student->next_ = NULL;
if (*head == NULL)
*head=new_student;
else {
struct student_record_node *temp = *head;
while (temp->next_ != NULL) {
temp = temp->next_;
}
temp->next_=new_student;
}
}
}
答案 0 :(得分:0)
我在您的代码中看到了一些问题: -