实验室中0x6BE20E11 (ucrtbased.dll) 的未处理异常.exe: 0xC0000005:访问冲突读取
Unhandled exception at 0x6BE20E11 (ucrtbased.dll) in labs.exe: 0xC0000005: Access violation reading location 0x0000004D
看起来我的函数makeUpper中存在错误。我尝试了指针和其他一些方法,但没有用。以下是排序中的内容.txt :
Michigan
Montana
New York
Alabama
WYOMING
South Carolina
mISSISSIPPI
Iowa
ohio
我的目标是将所有字母大写并按字母顺序列出。请帮助我。
#include <stdio.h>
#include <string.h>
#include <ctype.h>
void bubblesort(char line[][30], int n);
void swapStrings(char *first[], char *second[]);
void makeUpper(char first[][30], char upperFirst[][30]);
int main()
{
char state[NUM][30];
char upper[NUM][30];
int i, nspot;
FILE* infile;
/*Read file into first array.*/
infile = fopen("sorting.txt", "r");
if (infile == 0)
{
printf("trouble opening file.n");
return(0);
}
i = 0;
while ((fgets(state[i], 30, infile)) != NULL)
{
nspot = strlen(state[i]) - 1;
if (state[i][nspot] == 'n')
state[i][nspot] = ' ';
i++;
}
makeUpper(state, upper);
bubblesort(upper, NUM);
for (i = 0; i < NUM; i++)
{
printf("%sn", upper[i]);
}
fclose(infile);
return 0;
}
void bubblesort(char line[][30], int n)
{
int last;
int i;
for (last = n - 1; last >= 1; last--)
for (i = 0; i <= last - 1; i++)
{
if (strcmp(line[i], line[i + 1]) > 0)
swapStrings(&line[i], &line[i + 1]);
}
}
void swapStrings(char* first[], char* second[])
{
char swap[30];
strcpy(swap, first);
strcpy(first, second);
strcpy(second, swap);
}
void makeUpper(char first[][30], char upperFirst[][30])
{
int i,j;
int test;
for (i = 0; i < NUM; i++)
{
for (j = 0; j < (strlen(first[i])); j++)
{
if (first[i][j] > 90)
strcpy(upperFirst[i][j], toupper(first[i][j]));
else
strcpy(upperFirst[i][j], first[i][j]);
}
upperFirst[i][strlen(first[i])] = ' ';
}
}
取而代之的是:
strcpy(upperFirst[i][j], toupper(first[i][j]));
你需要这个:
upperFirst[i][j] = toupper(first[i][j]);
相关文章:
- 在 ******.exe 中0x00000000772CA267 (ntdll.dll) 处未处理的异常:0xC0000
- 在类 12.exe 中0x7B37FF80 (ucrtbased.dll) 引发异常: 0xC0000005:访问冲突读
- (此函数用于计算 SMA).在 FA.exe 中0x00509159引发异常: 0xC0000005:访问冲突读取位置0
- 在 Project70.exe 中的0x0F4D514F (vcruntime140d.dll) 引发异常:0xC000
- 错误 在测试.exe 0x76C9FD62时出现未经处理的异常:Microsoft C++异常:内存位置0x006FF8
- 在 Project1.exe 中0x00007FFCA550A839处发生未经处理的异常:Microsoft C++异常
- 在 Hello World.exe 中0x0F828F0E (ucrtbased.dll) 处未处理的异常: 0xC00
- 在 Myfile.exe 中0x00831D39时未处理的异常:0xC00000FD:堆栈溢出(参数:0x0000000
- 实验室中0x6BE20E11 (ucrtbased.dll) 的未处理异常.exe: 0xC0000005:访问冲突读取
- 在 "<name>.exe" 中0x00007FFF168E1657 (vcruntime140d.dll) 引发异常:0xC0000005:访问冲突写入位置0x0000000000000
- mystring.exe中的0x0FC9E559(ucrtbaseed.dll)的未经手法异常:0xc0000005:访
- 在candidateVotes.exe中以0x50E6F1C0(UCRTBASED.DLL)抛出异常.Exe:0xc00
- 在2.exe中的0x00DE181818的未经手法异常:0xc0000005:访问违规写作位置0xcd7cbe10
- NVIDIA 在 <work.exe>0xC0000005 中0x002a2da2未处理的异常:访问违规读取位置0x00000000
- 在 DirectXGame.exe 中0x00B84CD6出现未经处理的异常:0xC0000005:访问冲突读取位置0x
- OpenGL 和 GLUT 中0x009f240e处未处理的异常 - 101.exe:0xC0000005:访问违规写入
- Dijkstra 中0x001e1078 s_Algorithm.exe的未处理异常:0xC0000005:访问冲突读取位置0xbaadf00d
- BunkerBuilder.exe中0x0070C75C处的首次机会异常:0xC0000005:写入位置0xCCCCC0
- CPP_TEST.exe中0x7604c128处未处理的异常:0xC00000FD:堆栈溢出
- Quick.exe中0x003714e9处未处理的异常:0xC00000FD:堆栈溢出