鱼C论坛

 找回密码
 立即注册
查看: 2662|回复: 3

关于结构体的

[复制链接]
发表于 2012-2-4 09:55:00 | 显示全部楼层 |阅读模式

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

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

x
我这程序编译没错误的,怎么就是输不出结果来? 大家帮忙看看。
#include <stdio.h>
#include <MALLOC.H>
  struct student
  {
          char name[10];
          int age;
  };

     int main()
  {

          struct student *stu;
          stu=(student*)malloc(sizeof(struct student));
          printf("请输入数据:\n");
          printf("姓名:");
          scanf("%s",stu->name);
          printf("年龄:");
          scanf(" %d",stu->age);
          printf("姓名 年龄\n");
          printf("%s%d\n",stu->name,stu->age);
      
         }
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2012-2-4 10:13:59 | 显示全部楼层
  1. #include <stdio.h>
  2. #include <MALLOC.H>
  3.   struct student
  4.   {
  5.           char name[10];
  6.           int age;
  7.   };

  8.      int main()
  9.   {

  10.           struct student *stu;
  11.           stu=(student*)malloc(sizeof(struct student));
  12.           printf("请输入数据:\n");
  13.           printf("姓名:");
  14.           scanf("%s",stu->name);
  15.           printf("年龄:");
  16.           scanf(" %d",&stu->age);//这里需要取地址
  17.           printf("姓名 年龄\n");
  18.           printf("%s %d\n",stu->name,stu->age);
  19.          
  20.       
  21.          }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2012-2-4 10:14:13 | 显示全部楼层
  1. #include <stdio.h>
  2. #include <MALLOC.H>
  3.   struct student
  4.   {
  5.           char name[10];
  6.           int age;
  7.   };

  8.      int main()
  9.   {

  10.           struct student *stu;
  11.           stu=(student*)malloc(sizeof(struct student));
  12.           printf("请输入数据:\n");
  13.           printf("姓名:");
  14.           scanf("%s",stu->name);
  15.           printf("年龄:");
  16.           scanf(" %d",&stu->age);//这里需要取地址
  17.           printf("姓名 年龄\n");
  18.           printf("%s %d\n",stu->name,stu->age);
  19.          
  20.       
  21.          }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
 楼主| 发表于 2012-2-4 10:32:23 | 显示全部楼层
哦,对,难怪程序崩溃,原来是找不到地址。谢谢你啊!
小甲鱼最新课程 -> https://ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2025-11-11 02:33

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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