#include<string.h>
#define swn 3
#define namelen 20
#define codelen 10
#define fnamelen 80
#define buflen 80 //define前要加 #
#define num 16
int main()
{
char schoolwork[swn][num]= {"Chinese","Math","English"} //此处的num没有定义
struct student
{
int code[codelen+1]
char name[namelen+1]
char sex
int marks[swn]
} student1,student2,student3,student4
strcpy(student1.name, "Kris"),student1.code[0]=1,student1.sex='M'//字符串赋值要用strcpy()函数,头文件为#include<string.h>, 数字前不能加0,否则计算机默认为八进制数。
strcpy(student2.name,"Ella"),student2.code[0]=2,student2.sex='W'
strcpy(student3.name,"Luhan"),student3.code[0]=3,student3.sex='M'
strcpy(student4.name,"Daisy"),student4.code[0]=4,student4.sex='W'
int i = 1//要赋初值
if(i==1)
printf("%d,%s,%c,%c",student1.code[0],student1.name,student1.marks[0],student1.sex)//结构体里面的 code 是个数组,需要指定下标
else
printf("sorry")
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)