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.

如果我们把接收字符数组的长度设置的长一点,就可以避免这个问题。 

本文标签: checkfailurerunTIMEstr