C忘光了,就命!!!!为什么这个小程序调试通过,一执行就会被Windows Kill掉???

SteveYoung 2004-12-03 02:54:24

运行环境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;
}
...全文
144 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
SteveYoung 2004-12-03
  • 打赏
  • 举报
回复
谢谢大家!一切都已解决!
skfox 2004-12-03
  • 打赏
  • 举报
回复
另一个问题
char mapping[2][26]={"abcdefghijklmnopqrstuvwxyz","ngzqtcobmuhelkpdawxfyivrsj"};
数了一下,
abcdefghijklmnopqrstuvwxyz
ngzqtcobmuhelkpdawxfyivrsj
都是26个字符,后面还有一个结束符'\0'
已经越界了
sun428 2004-12-03
  • 打赏
  • 举报
回复
char *source 没有分配空间
一个指针未指向任何实体就被使用,属于”内存盗用”!因为该指针将随意指向内存中某一单元,轻则误取或破坏其他实体的值,重则破坏操作系统的工作。
rowdy 2004-12-03
  • 打赏
  • 举报
回复
楼上的没错,你的char *source 没有分配空间
sun428 2004-12-03
  • 打赏
  • 举报
回复
末尾要加的是getch()
而不是getchar()吧

头文件是 #include "conio.h"
积木 2004-12-03
  • 打赏
  • 举报
回复
你的char *source 没有分配空间,当然要写向下面的代码。
char *source = (char*)malloc(sizeof(char)*100);
最后要写
free(source);
SteveYoung 2004-12-03
  • 打赏
  • 举报
回复
谢谢楼上2位的回答,请问tsingien(Read The F**king Source Code),如果说这里不好,该怎么改进呢?
tsingien 2004-12-03
  • 打赏
  • 举报
回复
char *source = NULL;
printf("Please input a string :");
scanf("%s", source);
这样不好吧
Amour81 2004-12-03
  • 打赏
  • 举报
回复
最后加个GETCHAR()语句。
别忘记加头文件。

69,336

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧