#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 ;
}
两头堵模型
最新推荐文章于 2021-11-24 13:02:16 发布
1391

被折叠的 条评论
为什么被折叠?



