请指出错误啊
#include<stdio.h>#include<string.h>
int main(void)
{
char char1[20];
char char2[20];
char *p,*q;
int m;
int n=0;
p=char1;
q=char2;
printf("Pleaese input the string1:\n");
scanf("%s",char1);
printf("the location that you want is :\n");
scanf("%d",&m);
//len=strlen(char1);
while(n<m-1)
{
n++;
p++;
}
while(*p!='\0')
{
*q=*p;
p++;
q++;
}
*q='\0';
程序代码:
/*for(p=char1;p<char1+m-1;p++); if(*p!='\0') { for(q=char2;q<char2+m;q++) { *q=*p; p++; q++; } *q='\0'; }*/printf("%s\n",char2);
return 0;
}
我用了两种方法来复制部分字符串,为什么第一种可以,而第二种却不行呢?第二种运行结果是乱码,求指教