C访问冲突写入位置
我刚刚编译了这段代码,它向我显示了以下错误: Sample7.exe中0x0F2FC4DA(ucrtbased.dll)处引发异常:0xC0000005:访问冲突读取位置0x979436 我真的不知道这个错误意味着什么,因为我刚刚用了几个月的C。我也尝试过在其他网站上寻找帮助,但没有找到任何帮助C访问冲突写入位置,c,exception,C,Exception,我刚刚编译了这段代码,它向我显示了以下错误: Sample7.exe中0x0F2FC4DA(ucrtbased.dll)处引发异常:0xC0000005:访问冲突读取位置0x979436 我真的不知道这个错误意味着什么,因为我刚刚用了几个月的C。我也尝试过在其他网站上寻找帮助,但没有找到任何帮助 #include<stdio.h> #include<conio.h> #include<string.h> #include<stdlib.h> int
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
int i = 0, n, length = 0;
char *abc;
printf("\n Enter size of array: ");
scanf_s("%d", &n);
abc = new char[n];
printf("\n Enter symbols: ");
scanf_s("%s", abc);
length = strlen(abc);
for (i = 0; i <= n; i++)
{
printf("\n Your array: ", abc);
while (length = 10)
{
if (abc[i] >= 'A' && abc[i] <= 'Z')
{
abc[i] = ' ';
}
printf("\n Your array after deleting A-Z symbols",abc);
}
}
delete[]abc;
_getch();
return 0;
#包括
#包括
#包括
#包括
int main()
{
int i=0,n,长度=0;
char*abc;
printf(“\n输入数组大小:”);
扫描频率(“%d”和“&n”);
abc=新字符[n];
printf(“\n输入符号:”);
扫描单位(“%s”,abc);
长度=strlen(abc);
对于(i=0;i='A'&&abc[i]您收到此错误,因为您正在访问分配空间之外的内存。我猜您正在访问字符数组边界之外的索引。您需要逐行调试代码,以查看发生此情况的位置
在第一次查看代码时,我发现了以下错误
for(i=0;i首先,你的罪魁祸首是scanf_s(“%s”,abc);
因为当你通过scanf
读取字符串时,你需要提供字符串的大小,如scanf_s(“%s”,abc,n);
。
您还需要在代码中进行一些更正。您可以从concur输入数组的大小。例如输入数组的大小:10
,您在此处输入了10。现在数组的大小是10,因此您的循环应该从0-9总共10个位置继续,因此For循环应该是For(i=0;i='A'&&abc[i]在C中没有new和delete关键字。幻数10的含义是什么?在C中没有运算符new和delete。
#include "stdafx.h"
#include "stdafx.h"
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
int i = 0, n, length = 0;
char *abc;
printf("\n Enter size of array: ");
scanf_s("%d", &n);
abc = new char[n];
printf("\n Enter symbols: ");
scanf_s("%s", abc, n);//your scanf_s function was wrongly define.This one is correct.
printf("\n Your array1: %s", abc);
for (i = 0; i < n; i++)
{
printf("\n Your array: %s", abc);
//while (length == 10) You don't need this while loop at all
//{
if (abc[i] >= 'A' && abc[i] <= 'Z')
{
abc[i] = ' ';
}
//}
printf("\n Your array after deleting A-Z symbols :%s", abc);
}
delete[]abc;
_getch();
return 0;
}