admin管理员组文章数量:1618699
先上代码:
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(void)
{
//zifuchuan();
char str[5]; // 接收的字节数必须尽量超过预计的长度,否则会报错。
printf("input string1: \n");
int a = scanf("%s ", str);
printf("scanf的返回值为:%d\n", a);
if (a)
{
printf("output String : %s\n", str);
}
system("pause");
//return 0;
return EXIT_SUCCESS;
}
用一个字符数组来接受输入的字符串,如果输入字符长度超过这个数组长度,那么就会报错:
Run-Time Check Failure #2 - Stack around the variable 'str' was corrupted.
如果我们把接收字符数组的长度设置的长一点,就可以避免这个问题。
版权声明:本文标题:Run-Time Check Failure #2 - Stack around the variable ‘str‘ was corrupted. 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/xitong/1728786094a1173343.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论