C忘光了,就命!!!!为什么这个小程序调试通过,一执行就会被Windows Kill掉???
运行环境VC++ 6.0 + Windows XP SP2
----------
# include < stdio.h >
# include < string.h >
char *Encipher( char * );
void main()
{
char *source = NULL;
printf("Please input a string :");
scanf("%s", source);
source = Encipher( source );
printf("The string has been enciphered to: \"%s\"", source );
}
char *Encipher( char *t )
{
unsigned j = 0;
unsigned i = 0;
char mapping[2][26]={"abcdefghijklmnopqrstuvwxyz","ngzqtcobmuhelkpdawxfyivrsj"};
char *temp = t;
for( i; i <= strlen(t); i++ )
{
for( j=0; j <= 25; j++ )
if(mapping[0][j] == *temp)
{
*temp = mapping[1][j];
break;
}
temp++;
}
return t;
}
问题点数:70、回复次数:9Top
1 楼Amour81(玛里奥)回复于 2004-12-03 14:58:36 得分 10
最后加个GETCHAR()语句。
别忘记加头文件。Top
2 楼tsingien(Read The F**king Source Code)回复于 2004-12-03 14:59:48 得分 10
char *source = NULL;
printf("Please input a string :");
scanf("%s", source);
这样不好吧Top
3 楼SteveYoung(Fuck CCTV to die)回复于 2004-12-03 15:04:36 得分 0
谢谢楼上2位的回答,请问tsingien(Read The F**king Source Code),如果说这里不好,该怎么改进呢?Top
4 楼goodboy1881(积木)(谁都别拦着我在水源升星)回复于 2004-12-03 15:13:29 得分 10
你的char *source 没有分配空间,当然要写向下面的代码。
char *source = (char*)malloc(sizeof(char)*100);
最后要写
free(source);Top
5 楼sun428(Born to Win)回复于 2004-12-03 15:40:29 得分 10
末尾要加的是getch()
而不是getchar()吧
头文件是 #include "conio.h"Top
6 楼rowdy(阿丘)回复于 2004-12-03 15:43:19 得分 10
楼上的没错,你的char *source 没有分配空间Top
7 楼sun428(Born to Win)回复于 2004-12-03 15:44:52 得分 10
char *source 没有分配空间
一个指针未指向任何实体就被使用,属于”内存盗用”!因为该指针将随意指向内存中某一单元,轻则误取或破坏其他实体的值,重则破坏操作系统的工作。Top
8 楼skfox(sky)回复于 2004-12-03 16:22:43 得分 10
另一个问题
char mapping[2][26]={"abcdefghijklmnopqrstuvwxyz","ngzqtcobmuhelkpdawxfyivrsj"};
数了一下,
abcdefghijklmnopqrstuvwxyz
ngzqtcobmuhelkpdawxfyivrsj
都是26个字符,后面还有一个结束符'\0'
已经越界了Top
9 楼SteveYoung(Fuck CCTV to die)回复于 2004-12-03 21:07:37 得分 0
谢谢大家!一切都已解决!Top




