两头堵模型

来源:互联网 发布:怪物猎人帅哥捏脸数据 编辑:程序博客网 时间:2024/04/28 15:42
#include <stdio.h>#include <stdlib.h>#include <string.h>//两头堵模型 void getcount(char *str,int *mount){int i,j; i = 0;j = 0;if(str==NULL){return -1;}//int mount;j = strlen(str)-1;//isspace为内置函数 while(isspace(str[i])&&str[i]!='\0'){i++;}while(isspace(str[j])&&str[j]!='\0'){j--;}//printf("%d",*mount);*mount = j-i+1;}//去除字符串前后空格 中间不管int trimspace(char *str,char *newstr){char *p = str;int ncount = 0;int i,j=0;if(str == NULL || newstr ==NULL){printf("func trimspace() is error!");return -1;}i = 0;j = strlen(p)-1;while(isspace(p[i])&&p[i]!='\0'){i++;}while(isspace(p[j])&&p[j]!='\0'){j--;}ncount = j-i+1;strncpy(newstr,str+i,ncount);newstr[ncount] = '\0';return 0;}void main(){//求非空格的字符串的长度 char *p = "   abcdefg    ";char buf[1024]="   abcdefg    ";//int mount=0;//getcount(p,&mount);trimspace(p,buf);printf("%s",buf);return ;}


0 0