//remove the right space of the string.
char * strtrimr(char *pstr)
{
int i;
i=strlen(pstr)-1;
while((pstr[i]==' ')&&(i>-1))
{
pstr[i]='\0';
i--;
printf("%d\n",i);
};
}
int main()
{
char *p=" abcdef . ";
// char p[]=" abcdef . ";
// int a=2;
printf("%s%d\n",p,a);
printf("%s%d\n",strtrimr(p),a);
getchar();
return 0;
}
char p[]=" abcdef . ";
char *p=" abcdef . ";
两个不同之处 p[]和他的值放在栈中,可以改变
char *p=" abcdef . "; p放在栈中,其值放在静态区域,无法改变。
所以上述程序运行就出错。