#include <stdio.h>
#include <string.h>
#include <ctype.h>
int get_count_non_space(char *str, int * count_p)
{
int i = 0;
int j = strlen(str)-1;
int ncount = 0;
if (str == NULL || count_p == NULL) {
fprintf(stderr, "str == NULL, count_p == NULL\n");
return -1;
}
while (isspace(str[i]) && str[i] != '\0')
{
i++;
}
while (isspace(str[j]) && j > i)
{
j--;
}
ncount = j-i+1;
*count_p = ncount;
return 0;
}
int main(void)
{
char *p = " abcdefg ";
int ret = 0;
int ncount = 0;
ret = get_count_non_space(p, &ncount);
if (ret < 0) {
fprintf(stderr, "get_count_non_space err, ret = %d\n", ret);
return 0;
}
printf("ncount = %d\n", ncount);
return 0;
}
两头堵模型
最新推荐文章于 2021-11-24 13:02:16 发布