新手求教

问也去 2018-01-27 05:45:13
# include <stdio.h>
int main()
{
int n;
char a[50];
float b;
printf
("请输入你的学号:");
scanf
("%d", &n);
printf
("请输入你的姓名:");
scanf
("%s", &a);
printf
("请输入你的工资:");
scanf
("%f", &b);
printf

("你的学号,姓名,工资分别是:%d\n%s\n%0.2f", n, a, b);




}
代码在vc6.0中可以运行,但是放在vs2015中却显示:0x0F8FDDF4 (ucrtbased.dll)处(位于 sx6.exe 中)引发的异常: 0xC0000005: 写入位置 0x00B40000 时发生访问冲突。

如有适用于此异常的处理程序,该程序便可安全地继续运行。
求教为什么会这样,或者应该怎么改正才能在vs中运行。
...全文
1143 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
binarywz 2018-02-01
  • 打赏
  • 举报
回复
冒个泡。。。
「已注销」 2018-01-31
  • 打赏
  • 举报
回复
vs现在用scanf_s替代scanf了
leetow2006 2018-01-31
  • 打赏
  • 举报
回复
scanf("%s", &a);这个有问题吧,a是数组名,就是数组的首地址,所以scanf("%s", a);
kongrenxin 2018-01-31
  • 打赏
  • 举报
回复
代码没问题, VS2015编译时需要在 预处理器->预处理器定义里添加一个_CRT_SECURE_NO_WARNINGS,否则会报scanf不安全的错误(如楼上所说用scanf_s,如果想继续用scanf就按前面说的添加一个_CRT_SECURE_NO_WARNINGS就OK)
Kali_128 2018-01-30
  • 打赏
  • 举报
回复
推荐看一下scanf的原型
int scanf(const char *format, ...);
The  scanf()  family  of  functions  scans input according to format as
       described below.  This format may  contain  conversion  specifications;
       the  results from such conversions, if any, are stored in the locations
       pointed to by the pointer arguments that follow format.   Each  pointer
       argument  must  be of a type that is appropriate for the value returned
       by the corresponding conversion specification.

       If the number of conversion specifications in format exceeds the number
       of  pointer  arguments,  the  results  are undefined.  If the number of
       pointer arguments exceeds the number of conversion specifications, then
       the excess pointer arguments are evaluated, but are otherwise ignored.

       The  scanf() function reads input from the standard input stream stdin,
       fscanf() reads input from the stream pointer stream, and sscanf() reads
       its input from the character string pointed to by str.
自信男孩 2018-01-30
  • 打赏
  • 举报
回复
scanf("%s", a);
去掉a前的&;因为a是字符数组,数组名本身就是地址,因此不需要加&;
觉皇嵌入式 2018-01-27
  • 打赏
  • 举报
回复
vc6编译环境很低,你换c-free试试,程序没啥问题
faihung 2018-01-27
  • 打赏
  • 举报
回复
代码在vc6.0中可以运行,说明代码没有问题。 VS2015在创建工程的时候,和vc6.0是不一样的,很明显VS2015的编译环境你不熟悉。你百度一下、关于vs单个文件编译运行的问题。
大米粥哥哥 2018-01-27
  • 打赏
  • 举报
回复
输入到a数组的时候 不要加& 只写个a试试 scanf(.....,&a) -> scanf(...,a)

69,336

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧