去掉一个字符串首尾的0
#include<stdio.h>
#include<string.h>int main()
{
int i=0,j=0,k=0,z=0;
char aa[10];
printf("please input a string!\n");
gets(aa);
k=strlen(aa);
z=k-1;
while(aa[z]=='0')
{
--z;
}
int x=0,y=0;
while(aa[y]=='0')
{
y++;
}
for(x=y;x<z+1;x++)
{
printf("%c",aa[x]);
}
printf("\n");
return 0;
}
输出结果:
liuzj@ET302Buildver:~/zhanghong$ gcc qu0.c
qu0.c: In function ‘main’:
qu0.c:8:2: warning: ‘gets’ is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations]
gets(aa);
^
/tmp/cch8uYf9.o:在函数‘main’中:
qu0.c:(.text+0x45): 警告: the `gets' function is dangerous and should not be used.
liuzj@ET302Buildver:~/zhanghong$ ./a.out
please input a string!
0ffg0
ffg