字符串数组的一个问题
#include <stdio.h>#include <string.h>
void fact_calc(int m,char str1[]);
int jiecheng (int s);
int main()
{
char str[20];
int n,
i;
printf("Enter an integer between 0 ");
printf("and 9 or -1 to quit => ");
scanf("%d",&n);
fact_calc(n,str);
printf("%d",n);
for(i=0;i<strlen(str);i++)
printf("%c",str[i]);
printf(" = %d\n",jiecheng(n));
}
void fact_calc(int m,char str1[])
{
int l,
n;
char c[20];
char chucun[20];
char insert[]="X";
int i;
n=m+48;
str1[0] = '!';
str1[1] = '=' ;
str1[2] = '\0';
for(l=0;l<m;l++,n--)
chucun[l]=n;
chucun[l+1]='\0';
for(i=1;i<=9;i+=2)
{
strcpy(c,&chucun[i]);
strcpy(&chucun[i],insert);
strcat(chucun,c);
}
strcat(str1,chucun);
str1[strlen(str1)]='\0';
}
int jiecheng (int s)
{
if(s==0)
return 1;
else {
int result = jiecheng(s-1)*s;
return result;
}
}
输入6,输出"6!=6x5x4x3x2x1=720",我的代码为甚么只有在输入六的时候运行,别的数不行,并且=号前面一个问号?求解!