一些自用的c函数
来源:互联网 发布:java监控系统 编辑:程序博客网 时间:2024/06/06 03:43
删除字符串中多余的空格,这个代码很烂,将就吧。
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 false;
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 false;
6 if(access(cmd_path,F_OK) == 0)
7 {
8 return true;
9 }
10
11 return false ;
12
13 }
0 0
- 一些自用的c函数
- [自用]C语言函数
- 指针和函数的一些格式(自用)
- 一些自编自用的函数_不断更新不断改进
- c 函数例子(学习自用)
- 【自用】关于欧拉函数以及逆元的一些模板
- (自用)基于C关于JAVA的一些细碎语法知识(一)
- android学习收藏的一些网址,自用~
- matlab一些常用的命令(自用)
- 自用简单的一些小Utils
- linux下的一些命令(自用)
- 自用函数
- c的一些函数(转)
- c语言的一些函数
- c的一些函数(转)
- c语言字符串 数字转换函数大全转(自用)
- 一些自用工具备忘
- 一些学习笔记,自用
- 交叉编译libconv
- 2013年06月 八个短对话 第三套
- mount的api使用笔记
- write error:file too large!!!
- c调用Api设置linux时间
- 一些自用的c函数
- c通过system取得分区信息
- 主引导记录(MBR)分析
- 开发板上挂载NTFS分区
- 给定一个硬盘标识,umout掉所有相关挂载
- linux读取硬盘指定扇区
- strtok_r函数学习
- 【转】收藏:shell目录管理
- 四个预编译宏:__FILE__,__LINE__,__DATE__,__TIME__