一些自用的c函数

删除字符串中多余的空格,这个代码很烂,将就吧。

 

 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 }

 

删除字符串中的所有空格字符:

 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 }

检查文件是否存在

 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 }

 

转载于:https://www.cnblogs.com/jevan/archive/2012/08/24/2654452.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值