|
发表于 2016-3-21 01:00:24
|
显示全部楼层
本帖最后由 ℡.xiao敏 于 2016-3-21 01:43 编辑
那是百度云管家。并不是迅雷。
还有,出错原因和危险都很多。
首先:
如果
用户在输入用户号码的时候输入char,会崩。
如果
用户在输入用户名字的时候输入int,也会崩。
你的%s和%d都要先判断才能植入啊。
还有,你scanf_s来的字符串,存入结构,可你结构里面的都是指针啊,并没有空间呐。你要先有空间才能存字符串啊。所以把结构改下。
还有scanf_s参数还有一个的……scanf_s最后一个参数是缓冲区的大小,表示最多读取n-1个字符.
改成这样就可以了:
- struct stu
- {
- int num;
- char name[128];
- char sex[128];
- char dizhi[512];
- };
- void print(stu student)
- {
- printf("the student's num is %d\n", student.num);
- printf("the student's name is %s\n", student.name);
- printf("the student's sex is %c\n", student.sex);
- printf("the student's dizhi is %s\n", student.dizhi);
- }
- void main()
- {
- stu student1 = {0}; //创建结构先初始化一下。不然就会输出很多莫名其妙的东西。
- printf("please input the information of the student :\n");
- printf("please input the student's num:\n");
- scanf_s("%d", &student1.num);
- printf("please input the student's name:\n");
- scanf_s("%s", &student1.name,128);
- printf("please input the student's sex:\n");
- scanf_s("%s", &student1.sex,128);
- printf("please input the student's dizhi;\n");
- scanf_s("%s", &student1.dizhi,512);
- print(student1);
- system("pause");
- }
复制代码 |
评分
-
查看全部评分
|