编译器错误 C2198
#include<stdio.h>
#include"student.h"
int main()
{
// student 1
STUDENT lux = Createstudent(2003056789, "lux", "aa", "ren");
printf("NAME:%s\n", GetNameFromStudent(lux));
// student 2
STUDENT a = Createstudent(2004069876, "bb", "cc");
printf("NAME:%s\n", GetNameFromStudent(a));
printstudent(a);
// student 3
STUDENT b = Createstudent("2003081234-DD EE gg");
printf("NAME:%s\n", GetNameFromStudent(b));
printstudent(b);
// student 4
STUDENT c = Createstudent("2003074521-QQ RR YY");
printf("NAME:%s\n", GetNameFromStudent(c));
printstudent(c);
// student 5
STUDENT d = Createstudent("2003017623-MM NN JJ");
printf("NAME:%s\n", GetNameFromStudent(d));
printstudent(d);
return 0;
}
这个是我的头文件
#pragma once
#define MAXSIZE 25
typedef struct student
{
int studentnum;
char firstname[MAXSIZE];
char lasttname[MAXSIZE];
char middelname[MAXSIZE];
}STUDENT;
STUDENT Createstudent(int, char[], char[], char[]);
void printstudent(STUDENT);
这是另一个c文件
#define _CRT_SECURE_NO_WARNINGS
#include"student.h"
#include<stdio.h>
#include<string.h>
STUDENT Createstudent(int StudentNum, char lasttname[MAXSIZE], char firstname[MAXSIZE], char middelname[MAXSIZE])
{
STUDENT s;
s.studentnum = StudentNum;
strncpy(s.lasttname, lasttname, MAXSIZE);
strncpy(s.firstname, firstname, MAXSIZE);
strncpy(s.middelname, middelname, MAXSIZE);
return s;
}
void printstudent(STUDENT student)
{
int i;
for (i = 0; i < 5; i++)
{
if (student.middelname[i] = '\0') //this mean nothing on middlename
{
printf("%d-%s,%s", student.studentnum, student.lasttname, student.firstname);
}
else
{
printf("%d-%s,%c", student.studentnum, student.lasttname, student.firstname, student.middelname[0]);
}
}
}