各位大侠,请帮我看看这段代码哪里错了,谢谢(俺是新手啊)
// insert one character string into another string.
#include <stdio.h>
#include <string.h>
void insertString (char source[], char insert[], int index);
int main (void)
{
char source[20] = "the wrong son";
char insert[] = "per";
int index = 10;
int showWin;
insertString (source, insert, index);
printf ("The source string now is : %s", source);
scanf ("%i", &showWin);
return 0;
}
void insertString (char source[], char insert[], int index)
{
int i, j;
char reserve[10];
for ( i = 0; source[index + i] != '\0'; ++i )
{
reserve[i] = source[index + i];
}
reserve[i] = '\0';
for ( i = 0; insert[i] != '\0'; ++i )
{
source[index + i] = insert[i];
}
for ( j = 0; reserve[j] != '\0'; ++i )
{
source[index + i + j] = reserve[j];
}
source[index + i + j] = '\0';
}
调试时的出错信息:
“exercise7.exe”: 已加载“D:\常用文件夹\project\chapter 10\exercise7\Debug\exercise7.exe”,已加载符号。
“exercise7.exe”: 已加载“C:\Windows\System32\ntdll.dll”,Cannot find or open the PDB file
“exercise7.exe”: 已加载“C:\Windows\System32\kernel32.dll”,Cannot find or open the PDB file
“exercise7.exe”: 已加载“C:\Windows\System32\KernelBase.dll”,Cannot find or open the PDB file
“exercise7.exe”: 已加载“C:\Windows\System32\msvcr100d.dll”,已加载符号。
exercise7.exe 中的 0x003915fe 处最可能的异常: 0xC0000005: 写入位置 0x001a0000 时发生访问冲突
exercise7.exe 中的 0x777a6194 处有未经处理的异常: 0xC0000005: Access violation
[解决办法]
这个地方
for ( j = 0; reserve[j] != '\0'; ++i )
应该写成
for ( j = 0; reserve[j] != '\0'; ++j )
[解决办法]
细心++