如何去掉字符串开头的0和结尾的0?

去掉一个字符串首尾的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



版权声明:本文为Makefilehoon原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。