删除字符串中多余的空格,这个代码很烂,将就吧。
1 void del_multi_space(char* src)
2 {
3 if(!src) return;
4
5 int src_len=strlen(src);
6 char* dest=(char*)malloc(src_len + 1) ;
7 memset(dest,0,src_len + 1);
8
9 int i,j=0;
10 for(i=0;i<src_len;i++)
11 {
12 if(!((src[i] == 32)&&(src[i+1] == 32)))
13 dest[j++] = src[i];
14
15 }
16 dest[j]='\0';
17 memset(src,0,src_len + 1);
18 memcpy(src,dest,strlen(dest));
19 printf("%s",dest);
20 free(dest);
21
22 }
2 {
3 if(!src) return;
4
5 int src_len=strlen(src);
6 char* dest=(char*)malloc(src_len + 1) ;
7 memset(dest,0,src_len + 1);
8
9 int i,j=0;
10 for(i=0;i<src_len;i++)
11 {
12 if(!((src[i] == 32)&&(src[i+1] == 32)))
13 dest[j++] = src[i];
14
15 }
16 dest[j]='\0';
17 memset(src,0,src_len + 1);
18 memcpy(src,dest,strlen(dest));
19 printf("%s",dest);
20 free(dest);
21
22 }
删除字符串中的所有空格字符:
1 void del_all_space(char* str)
2 {
3 char* p=str;
4 int i=0;
5 while((*p) != '\0')
6 {
7 if((*p) != ' ')
8 {
9 str[i++] = *p;
10
11 }
12 p++;
13 }
14 str[i]='\0';
15 }
2 {
3 char* p=str;
4 int i=0;
5 while((*p) != '\0')
6 {
7 if((*p) != ' ')
8 {
9 str[i++] = *p;
10
11 }
12 p++;
13 }
14 str[i]='\0';
15 }
检查文件是否存在
1 static bool check_file_exist(const char* cmd_path)
2 {
3 printf("%s == %d cmd_path=%s\n" ,__FUNCTION__,__LINE__,cmd_path);
4
5 if(!cmd_path) return -1;
6 if(access(cmd_path,F_OK) == 0)
7 {
8 return true;
9 }
10
11 return false ;
12
13 }
2 {
3 printf("%s == %d cmd_path=%s\n" ,__FUNCTION__,__LINE__,cmd_path);
4
5 if(!cmd_path) return -1;
6 if(access(cmd_path,F_OK) == 0)
7 {
8 return true;
9 }
10
11 return false ;
12
13 }