好兄弟们,急救急救。
我使用的是vs2015编译软件,今天学习编写时,代码如下:#include <stdio.h>
#define PRAISE "You are an extraordinary being."
int main(void)
{
char name;
printf("What`s your name?\n");
scanf_s("%s", name);
printf("Hellow,%s. %s\n", name, PRAISE);
return 0;
}
这个是新的一章的内容,我写完后调试程序,但是显示访问冲突:
“73页案例.exe”(Win32): 已加载“C:\Windows\SysWOW64\vcruntime140d.dll”。无法查找或打开 PDB 文件。
0x7C520B5C (ucrtbased.dll)处(位于 73页案例.exe 中)引发的异常: 0xC0000005: 写入位置 0x00D00000 时发生访问冲突。
0xFEFEFEFE 处有未经处理的异常(在 73页案例.exe 中): 0xC00001A5: 检测到无效的异常处理程序例程。 (参数: 0x00000003)。
程序“ 73页案例.exe”已退出,返回值为 0 (0x0)。
请问具体该怎么处理,求大佬指导,谢谢。 这样试试
#include <stdio.h>
#define PRAISE "You are an extraordinary being."
int main(void)
{
char name;
printf("What`s your name?\n");
scanf("%s", name);
printf("Hellow,%s. %s\n", name, PRAISE);
return 0;
} 小甲鱼的铁粉 发表于 2020-11-28 12:26
这样试试
还是不可以,{:5_100:} #include <stdio.h>
#define PRAISE "You are an extraordinary being."
int main(void)
{
char name;
printf("What`s your name?\n");
scanf_s("%s",name,20); // 若名字长,将20再改大哟
printf("Hellow,%s. %s\n", name, PRAISE);
return 0;
} 风过无痕1989 发表于 2020-11-28 16:27
这个是对的,但是为什么会这样呀,我上一个练习的代码也是这样的错误,但是我不知道怎么搞的,网上说要怎么怎么操作,但是我看不懂那些,你这个和书本上的不一样,改的东西是什么原理呢???谢谢 353500315 发表于 2020-11-28 16:49
这个是对的,但是为什么会这样呀,我上一个练习的代码也是这样的错误,但是我不知道怎么搞的,网上说要怎 ...
scanf_s,有时要求给出接收个数 风过无痕1989 发表于 2020-11-28 16:55
scanf_s,有时要求给出接收个数
大佬,我是调试程序的时候说访问冲突,scanf_s我之前已经打上去了,但是调试的时候还是有问题,不论是这个题,还是上个案例,都是这种情况。
#include <stdio.h>
#include <string.h>
#define DENSITY 62.4
int main()
{
float weight, volume;
int size, letters;
char name;
printf("Hi!What`s your first name?\n");
scanf_s("%s", name);
printf("%s,what`s your weight in pounds.\n", name);
scanf_s("%f", &weight);
size = sizeof name;
letters = strlen(name);
volume = weight / DENSITY;
printf("Well,%s,you volume is %2.2f cubic feet.\n", name, volume);
printf("Also,your first name has %d letters,\n", letters);
printf("and we have %d bytes to store it.\n", size);
return 0;
}
这是上个程序,调试后也是这样的情况。 353500315 发表于 2020-11-28 17:24
大佬,我是调试程序的时候说访问冲突,scanf_s我之前已经打上去了,但是调试的时候还是有问题,不论是这 ...
加上那个20就没有问题了
本帖最后由 353500315 于 2020-11-28 17:44 编辑
风过无痕1989 发表于 2020-11-28 17:38
加上那个20就没有问题了
那这个20是什么意思呀???
而且,:
#include <stdio.h>
#include <string.h>
#define DENSITY 62.4
int main()
{
float weight, volume;
int size, letters;
char name;
printf("Hi!What`s your first name?\n");
scanf_s("%s", name,20);
printf("%s,what`s your weight in pounds.\n", name);
scanf_s("%f", &weight);
size = sizeof name;
letters = strlen(name);
volume = weight / DENSITY;
printf("Well,%s,you volume is %2.2f cubic feet.\n", name, volume);
printf("Also,your first name has %d letters,\n", letters);
printf("and we have %d bytes to store it.\n", size);
return 0;
}
我已经加上了,但是还是不行,不知道为什么?
页:
[1]