简体   繁体   中英

Conflicting types for function 'read'?

I keep getting an error that says "conflicting types for function '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.

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.

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 ; you cannot use that name for a function in your program. Pick a more specific name for your function, eg readStudent() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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