数据丢失问题
程序功能:把字符串中的所有字符左移一个位置,第一个字符移到最后但是运行后第一个字符不见了,应该出现在最后一位的。我百思不得其解,请各位帮忙看看。
程序代码:#include <stdio.h>
void chg(char *s);
main()
{
char a[30],*p;
p=a;
printf("请输入一个长度小于30的字符串:");
gets (a);
chg(p);
printf("移动后:%s",p);
printf("\n");
}
void chg(char *s)
{
char c;
c=*s;
for(;*s!='\0';s++)
{
*s=*(s+1);
printf("\n%c\n",*s); //这是我为了调试程序加的
}
*s=c;
printf("\n%c\n",*s); //这是我为了调试程序加的
*(s+1)='\0';
}








