看板Programming
标 题请教c 语言的执行怪现象
发信站白色情迷 (Tue Mar 20 00:21:47 2007)
转信站ptt!ctu-reader!ctu-gate!news.nctu!news.ntu!mars.scc.ntnu!snowBBS
请教一下各位前辈...
以下有个C程式(写得不是很好啦,但可以跑),
执行结果在resulted string的尾巴会多出4个字元,
请问那是怎麽回事?要如何修改才不会跑出那4个字元?
谢谢罗~~
ps. 我用Dev C++4.9.9.2跑的
#include <stdio.h>
#include <string.h>
int main()
{
int i,j;
char origin[4];
char transfer(char *);
scanf("%s",origin);
printf("original string: %s\n",origin);
for(i=0;i<4;i++) {
result[i]=transfer(&origin[i]);
printf("resulted string: %s\n",result);
}
printf("resulted string: %s\n",result);
system("pause");
}
char transfer(char *o)
{
char table[7][7]={{'a','b','c','d','e','f','g'},
{'b','c','d','e','f','g','a'},
{'c','d','e','f','g','a','b'},
{'d','e','f','g','a','b','c'},
{'e','f','g','a','b','c','d'},
{'f','g','a','b','c','d','e'},
{'g','a','b','c','d','e','f'}};
char r;
if(*o==table[0][0])
r=table[1][0];
else if(*o==table[0][1])
r=table[1][1];
else if(*o==table[0][2])
r=table[1][2];
else if(*o==table[0][3])
r=table[1][3];
else if(*o==table[0][4])
r=table[1][4];
else if(*o==table[0][5])
r=table[1][5];
else if(*o==table[0][6])
r=table[1][6];
return(r);
}
--
╭╢师大资讯。白色情迷╟┬─ ⊙ Origin : snow.ice.ntnu.edu.tw
├╨→ 140.122.77.49←╜╰─ ☆ From : 59-117-35-53.dynamic.hinet.net