简体   繁体   English

函数“读取”的类型冲突?

[英]Conflicting types for function 'read'?

I keep getting an error that says "conflicting types for function 'read' ". 我不断收到一个错误,提示“函数类型为'read'冲突”。 My teacher wrote that function for our homework assignment, but it doesn't seem to be compiling correctly. 我的老师为我们的作业分配了该功能,但似乎编译不正确。 Here's the declaration of the functions before main. 这是main之前的函数声明。

void flush();
void branching(char);
void read(); // The one that isn't working
void add(char*, char*, char*, char*, struct student*);
void display();
void save(char* fileName);
void load(char* fileName);

Here's the read function: 这是读取功能:

void read()
{
char student_firstName[100];
char student_lastName[100];
char student_grade[30];
char student_level[100];

printf("\nEnter the student's first name:\n");
fgets(student_firstName, sizeof(student_firstName), stdin);

printf("\nEnter the student's last name:\n");
fgets(student_lastName, sizeof(student_lastName), stdin);

printf("\nEnter the student's grade (A+,A,A-,...):\n");
fgets(student_grade, sizeof(student_grade), stdin);

printf("\nEnter the student's education level (f/so/j/s):\n");
fgets(student_level, sizeof(student_level), stdin);

// discard '\n' chars attached to input; NOTE: If you are using GCC, you may need to comment out these 4 lines
student_firstName[strlen(student_firstName) - 1] = '\0';
student_lastName[strlen(student_lastName) - 1] = '\0';
student_grade[strlen(student_grade) - 1] = '\0';
student_level[strlen(student_level) - 1] = '\0';

add(student_firstName, student_lastName, student_grade, student_level, list);
printf("\n"); // newline for formatting
}

It's also saying implicit declaration of function 'read' is invalid in C99. 这也表示函数“ read”的隐式声明在C99中无效。

Does anyone know why this is happening and how to fix it? 有谁知道为什么会这样以及如何解决?

read() is a name used for a function in the C standard library ; read()C标准库中用于函数的名称; you cannot use that name for a function in your program. 您不能在程序中使用该名称作为函数。 Pick a more specific name for your function, eg readStudent() . 为您的函数选择一个更特定的名称,例如readStudent()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM