都市 发表于 2016-2-4 09:06:43

为什么不能进行下去了?

我的系统是win7装了C++的程序。学了小甲鱼的课程后,试着编写了下面的数据库程序,编译正常,可在输入学号后,就提示停止工作了。试着注释了几行代码,也没有用。请大牛帮看一下,为什么会这样?谢谢
#include<stdio.h>
#include<stdlib.h>

#define NUM 3

struct student
{
        int num;
//        char name;
        //int cj;
        //int clas;
        char addr;
}student;
void main()
{
        int i;
        printf("请录入学生信息:\n");
        for(i=1;i<NUM;i++)
        {
                printf("学号:");
                scanf("%d\n",student.num);
        //        printf("姓名:\n");
        //        scanf("%s\n ",student.name);
                //printf("成绩:\n");
                //scanf("%d\n ",student.cj);
                //printf("班级:\n");
                //scanf("%d\n",student.clas);
                printf("地址:\n");
                scanf("%s\n ",student.addr);
        }
        while (i<NUM)
        {
                printf("%2d%4s",student.num,student.addr);
        }
}

小甲鱼 发表于 2016-2-4 13:52:55

scanf 函数需要在变量前加 &,比如:

scanf("%d\n",student.num);
应该写成:

scanf("%d", &student.num);
具体请参考 scanf 函数文档:http://bbs.fishc.com/thread-67391-1-1.html

PS:不建议继续学习《零基础入门学习C语言》这个系列,现在已经录制了新版的《带你学C带你飞》代替。

都市 发表于 2016-2-4 14:14:12

谢谢,已经下了带你飞,正在学{:5_109:}
页: [1]
查看完整版本: 为什么不能进行下去了?