/***********************************************
*传入已经字符串的指针首地址*str和保存去除空格后的字符串地址(一般是数组地址)*newstr
*
**************************************************/inttrimSpace1(char*str,char*newstr){char*q = str;//新定义一个指针去接受传入的字符串地址,相当于接过字符串int i =0, j =strlen(str)-1;//定义变量i去指向字符串的起始段,定义变量j去指向字符串的尾端int ncount =0,ret =0;//定义保存数组长度,和返回值类型if(str==NULL&&newstr==NULL)//如果传入的地址为空,这返回错误码-1{
ret =-1;return ret;}while(isspace(q[i])&&q[i]!='\0')//从前往后扫描,如果前面遇到空格直接往后移动{
i++;}while(isspace(q[j])&&q[j]!='\0')//从后往前扫描,如果遇到空格直接往前移动{
j--;}
ncount = j - i +1;//求出字符串首尾非空格数的字符长度,即字符串长度strncpy(newstr, str + i, ncount);//将非空格的字符复制到newstr地址中
newstr[ncount]='\0';//在末尾加上字符结束符return0;}
intgetKeyByValue(char*keyvaluebuf,char*keybuf,char*valuebuf,int*len){//1、查找key是不是在母串中char*p = keyvaluebuf;int ret =0;if(keybuf==NULL||keyvaluebuf==NULL||valuebuf==NULL){
ret =-1;return ret;}
p = p +strlen(keybuf);//2、看有没有等号
p =strstr(p,"=");if(p==NULL){
ret =-2;return ret;}
p = p +strlen("=");//3、在等号后面,去除空格
ret =trimSpace1(p, valuebuf);*len =strlen(valuebuf);return0;}