两头堵模型
程序员文章站
2022-07-14 18:34:19
...
#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;
}
上一篇: 打造工业级推荐系统