鱼C论坛

 找回密码
 立即注册
查看: 1851|回复: 4

[已解决]结构体的问题

[复制链接]
发表于 2019-5-10 22:29:09 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
请问为啥下面会报错啊
最佳答案
2019-5-11 00:39:29
  1. #include <stdio.h>
  2. typedef struct
  3. {
  4.   int xuehao;// 如果写成xuehao[20]就是定义了一个长度为20的int型数组
  5.   char name[20];
  6.   char zhuanye[20];
  7.   int  year;//同理,如果写成year[20]就是定义了一个长度为20的int型数组
  8. }Student;

  9. int main(){
  10.   Student stu={19 , "wang" , "shuxue" , 2019};
  11.   printf("%d,%s,%s,%d\n",stu.xuehao,stu.name,stu.zhuanye,stu.year);
  12.   return 0;
  13. }
复制代码
99(RL)WZCWI2LG}O85}6]OV.png
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-5-10 22:49:27 | 显示全部楼层
  1. #include <stdio.h>

  2. typedef struct _student {
  3.         int  xuehao      ;
  4.         char name[20]    ;
  5.         char zhuanye[20] ;
  6.         int  year        ;
  7. } Student                ;

  8. int main(void)
  9. {
  10.         Student stu = {19 , "wang" , "shuxue" , 2019}                                          ;
  11.         printf("%d , %s , %s , %d\n" , stu . xuehao , stu . name , stu . zhuanye , stu . year) ;
  12. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-5-10 22:59:32 | 显示全部楼层
int xuehao[20]; int xuehao;
int year[20];  int year;
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-5-11 00:39:29 | 显示全部楼层    本楼为最佳答案   
  1. #include <stdio.h>
  2. typedef struct
  3. {
  4.   int xuehao;// 如果写成xuehao[20]就是定义了一个长度为20的int型数组
  5.   char name[20];
  6.   char zhuanye[20];
  7.   int  year;//同理,如果写成year[20]就是定义了一个长度为20的int型数组
  8. }Student;

  9. int main(){
  10.   Student stu={19 , "wang" , "shuxue" , 2019};
  11.   printf("%d,%s,%s,%d\n",stu.xuehao,stu.name,stu.zhuanye,stu.year);
  12.   return 0;
  13. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-5-11 11:01:48 | 显示全部楼层
结构体里int xuehao;跟int year别写成数组就行。
往数组里放对象要加上双引号("")

            
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-6 20:50

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表