C语言编译器VS2012问题

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C语言编译器VS2012问题相关的知识,希望对你有一定的参考价值。

这是我写的一个作业
# include <stdio.h>

struct student

char num[6];
char name[9];
char sex[3];
int age;
int score[3];
int sum;
double average;
;

void tidy (struct student * p);

int main (void)

struct student st[10];
int i, j;
for (i=0; i<10; i++)

printf ("print the num:");
scanf_s ("%s", st[i].num);
printf ("print the name:");
scanf_s ("%s",st[i].name);
printf ("print the sex:");
scanf_s ("%s",st[i].sex);
printf ("print the age:");
scanf_s ("%d", &st[i].age);
printf ("print the 3 score:");
for (j=0; j<3; j++)
scanf_s ("%d", &st[i].score[j]);
printf("\n");
printf ("-----------------------\n");


tidy (st);

printf ("学号 姓名 性别 年龄 数学 语文 英语 总和 平均分\n");
for (i=0; i<10; i++)

printf ("%s %s %s %d %d %d %d %d %lf\n", st[i].num, st[i].name, st[i].sex, st[i].age, st[i].score[0], st[i].score[1], st[i].score[2], st[i].sum, st[i].average);


return 0;


void tidy (struct student * p)

int i;
for (i=0; i<10; i++)

(p+i)->sum = (p+i)->score[1] + (p+i)->score[2] + (p+i)->score[3];
(p+i)->average = (p+i)->sum/3.0;



用VS2012不能完成输入(也不能这样说,输入是完成了,但不是我期望的那样,小生不会描述,劳烦大神用VS2012输入一下就 知道我到底想说什么了),但VC++6.0却可以,求解为什么

for (i=0; i<10; i++)

printf ("print the num:");
scanf_s ("%s", st[i].num, 6);
printf ("print the name:");
scanf_s ("%s",st[i].name, 9);
printf  ("print the sex:");
scanf_s ("%s",st[i].sex, 3);
printf ("print the age:");
scanf_s ("%d", &st[i].age, 1);
printf ("print the 3 score:");
for (j=0; j<3; j++)
    scanf_s ("%d", &st[i].score[j], 1);
printf("\\n");
printf ("-----------------------\\n");


scanf_s得像上面那么用,必须提供一个数字以表明最多读取多少位字符,比如你学号是用char [6]存的,后面就要规定个6表示最多用6个字节存学号。

如果你要像你之前那么用的话就用 scanf 不要用scanf_s

追问

原来如此,这是scanf_s的读取方式吗?

追答

vs是比较强大滴,你可以装个msdn2012,这个相当于帮助文档,会有函数的使用说明, 就可以查scanf_s的用法,下面还有例子的

参考技术A 这个回答很完美了。
请移步看一下。有不明白可以追问。请采纳。
http://zhidao.baidu.com/question/1110290532143052追问

已经打不开了!哭

追答

我试过了可以,刚才少了699.html
http://zhidao.baidu.com/question/1110290532143052699.html

追问

不是这个问题,我能够编译,也能够运行,就是输入数值部分不能和我预期的一样,想知道VS2012是怎样处理我输入的数据的

以上是关于C语言编译器VS2012问题的主要内容,如果未能解决你的问题,请参考以下文章

在vs2012中,如何创建c语言程序?

用VS2008如何编译.c,C语言文件?

visual studio2012中 c语言编译出来的程序怎么暂停啊

如何使用VS2013编写C语言? 包括编译连接和运行测试.

用VS2012如何执行C语言编写的程序?

C语言的编译器(IDE)及写第一个程序