我不断收到一堆错误:
- 参数 1 中的类型错误
- 重新声明之前声明的“getStudentData”
- “(不完整)结构 studnet”的未知字段“fname”。
任何反馈都将得到重视。谢谢
#include <stdio.h>
#include <stdlib.h>
struct student{
char fname[21];
char lname[21];
float gpa;
} str;
int getStudentData(struct studnet *current_ptr); // struct function format
int main(void){
struct student str;
getStudentData(str);
printf("Last Name: %s\n First Name: %s\n GPA: %.2f\n", str.fname, str.lname, str.gpa);
return 0;
}
int getStudentData(struct studnet *current_ptr){
FILE *studentFile; // declaring a pointer file variable
studentFile = fopen("StudnetData.txt", "r"); // format for fopen; file-variable = fopen(file_name, mode);
if ( studentFile == NULL){
printf("Error: Unable to open StudnetData.txt file\n"); //test for error
}
else {
fscan(studentFile, "%20s %20s has a GPA of %f\n"
, current_ptr->fname, current_ptr->lname, current_ptr->gpa);
// fscanf(file, format, ¶meter-1, ...)
fclose(studentFile); // The function fclose will close the file.
}
return 0;
}