标签:控制台 编译 应用程序 str get i++ dll for uber
下面的代码在编译,运行时没有问题,在输入内容是出现异常如下:
0x0F19B7EC (ucrtbased.dll)处(位于 ex6.exe 中)引发的异常: 0xC0000005: 写入位置 0x00740000 时发生访问冲突。
#include "stdafx.h"
#include <conio.h>
#include <stdio.h>
int main()
{
int NUM, I;
struct STUDENT
{
char NAME[30];
int AGE;
char ID[10];
};
struct STUDENT STD[100];
_cprintf("\nHow many student do you have ? Input the nuber;");
scanf_s("%d", &NUM);
for (I = 1; I <= NUM; I++)
{
_cprintf("\nInput student %d -- name:", I);
scanf_s("%s", &STD[I - 1].NAME);
_cprintf("\nInput student %d -- age:", I);
scanf_s("%d", &STD[I - 1].AGE);
_cprintf("\nInput student %d -- ID:", I);
scanf_s("%s", &STD[I - 1].ID);
}
_cprintf("\nTo see the RESULT,Press Any Key... ...");
_getch();
for (I = 1; I <= NUM; I++)
{
printf("\n student %d -- name: %s", I, STD[I - 1].NAME);
printf("\n student %d -- age: %d", I, STD[I - 1].AGE);
printf("\n student %d -- ID: %s", I, STD[I - 1].ID);
}
_cprintf("\nPress Any Key To EXIT... ...");
_getch();
return 0;
}
解决方法:
将上面的红色标记代码修改如下:
// ex6.cpp: 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <conio.h>
#include <stdio.h>
int main()
{
int NUM, I;
struct STUDENT
{
char NAME[30];
int AGE;
char ID[10];
};
struct STUDENT STD[100];
_cprintf("\nHow many student do you have ? Input the nuber;");
scanf_s("%d", &NUM);
for (I = 1; I <= NUM; I++)
{
_cprintf("\nInput student %d -- name:", I);
scanf_s("%s", &STD[I - 1].NAME,30);
_cprintf("\nInput student %d -- age:", I);
scanf_s("%d", &STD[I - 1].AGE);
_cprintf("\nInput student %d -- ID:", I);
scanf_s("%s", &STD[I - 1].ID,10);
}
_cprintf("\nTo see the RESULT,Press Any Key... ...");
_getch();
for (I = 1; I <= NUM; I++)
{
printf("\n student %d -- name: %s", I, STD[I - 1].NAME);
printf("\n student %d -- age: %d", I, STD[I - 1].AGE);
printf("\n student %d -- ID: %s", I, STD[I - 1].ID);
}
_cprintf("\nPress Any Key To EXIT... ...");
_getch();
return 0;
}
0x0F19B7EC (ucrtbased.dll)处(位于 ex6.exe 中)引发的异常: 0xC0000005: 写入位置 0x00740000 时发生访问冲突。
标签:控制台 编译 应用程序 str get i++ dll for uber
原文地址:http://www.cnblogs.com/TZB007/p/7615117.html