C applet - extract the effective length of the memory space pointed to by p after removing the spaces

//length of string after removing spaces

int trimSpaceStr01(char *p, int *mycount)

{
int ret = 0;
int ncount = 0;
int i, j;
i = 0;
j = strlen(p) -1;
while (isspace(p[i]) && p[i] != '\0')
{
i++;
}
while (isspace(p[j]) && j>0 )
{
j--;
}
ncount = j - i + 1;
*mycount  = ncount;
return ret;

}

// test case

#include "stdlib.h"
#include "stdio.h"
#include "string.h"

void main()
{
char *p = "     abcd     ";

int  ncount = 0;

        int rev = 0;

rev = trimSpaceStr01( p, &ncount);

        if(rev != 0)

        {

                printf("func trimSpaceStr01( ) err:%d;", ret);

        }

        printf("ncount:%d \n", ncount);

system("pause");
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325905184&siteId=291194637