各位大侠,请帮小弟我看看这段代码错哪了,多谢(俺是新手啊)
各位大侠,请帮我看看这段代码哪里错了,谢谢(俺是新手啊)
// 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 )
------解决方案--------------------
细心++
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------
关于自己是否适合编程的很简单的测试:
在报纸或杂志上随便找一段约1000字的文章,在Word中输入一遍。输完后再参考下面答案:
A里面有10处以上文字或标点错误
B里面没有文字或标点错误并敢为此跟人打赌
C里面没有文字或标点错误并且字体和排版完全与原稿一致
D打印在半透明的纸上和原稿重叠在一起检查一模一样,且自我感觉很有成就感
A不适合编程(理由:打字准确度偏低、粗心大意)
B初级程序员(理由:打字准确度很高、认真细致、自信、理解全角半角概念)
C高级程序员(理由:在B的基础上理解字体和排版也是电脑打印的重要因素、但相比D还不够偏执、精益求精、结果可验证)
D软件项目经理(理由:能针对项目给出令人信服的细致到极点的需求说明和典型测试用例。用户几乎挑不出毛病。专业!)
如果想从A变成B的话,到我的资源http://download.****.net/detail/zhao4zhong1/4084259里面下载“适合程序员的键盘练习”
------解决方案--------------------
新手还这样,我服了啊啊 啊啊啊
------解决方案--------------------
新手这样已经很不错了
// 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 )
------解决方案--------------------
细心++
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------
关于自己是否适合编程的很简单的测试:
在报纸或杂志上随便找一段约1000字的文章,在Word中输入一遍。输完后再参考下面答案:
A里面有10处以上文字或标点错误
B里面没有文字或标点错误并敢为此跟人打赌
C里面没有文字或标点错误并且字体和排版完全与原稿一致
D打印在半透明的纸上和原稿重叠在一起检查一模一样,且自我感觉很有成就感
A不适合编程(理由:打字准确度偏低、粗心大意)
B初级程序员(理由:打字准确度很高、认真细致、自信、理解全角半角概念)
C高级程序员(理由:在B的基础上理解字体和排版也是电脑打印的重要因素、但相比D还不够偏执、精益求精、结果可验证)
D软件项目经理(理由:能针对项目给出令人信服的细致到极点的需求说明和典型测试用例。用户几乎挑不出毛病。专业!)
如果想从A变成B的话,到我的资源http://download.****.net/detail/zhao4zhong1/4084259里面下载“适合程序员的键盘练习”
------解决方案--------------------
新手还这样,我服了啊啊 啊啊啊
------解决方案--------------------
新手这样已经很不错了