归纳整理Linux下C语言常用的库函数----内存及字符串控制及操作

在没有IDE的时候,记住一些常用的库函数的函数名、参数、基本用法及注意事项是很有必要的。

参照Linux_C_HS.chm的目录,我大致将常用的函数分为一下几类:

  • 1. 内存及字符串控制及操作
  • 2. 字符串转换
  • 3. 字符测试
  • 4. 文件操作
  • 5. 时间日期
  • 6. 常用数学函数
  • 7. 文件内容操作
  • 8. 文件权限控制
  • 9. 进程操作
  • 10. 线程操作
  • 11. Socket操作
  • 12. 信号处理
  • 13. 数据结构及算法


以下是对第一项 内存及字符串控制及操作 的归纳整理。

  • 已经不赞成使用的函数归类
*
*           函数名                                                   用途                                    替换方案
*1. int bcmp(const void *s1, const void *s2, size_t n);         compare byte sequences                        memcmp
*
*2. void bcopy(const void *src, void *dest, size_t n);          copy byte sequence                            memcpy Or memmove
*
*3. void bzero(void *s, size_t n);                              write zero-valued bytes                       memset
*
*4. char *index(const char *s, int c);                          locate character in string                    strchr
*
*5. char *rindex(const char *s, int c);                         locate character in string                    strrchr
*
  • 内存或字符串查找函数归类
*           函数名                                                   用途                                       备注
*1. void *memchr(const void *s, int c, size_t n);       scan memory for a character (Forward)       return a pointer to the matching byte or NULL if the
                                                                                                     character does not occur  in  the  given  memory area.
*
*2. void *memrchr(const void *s, int c, size_t n);      scan memory for a character  (Backward)      return a pointer to the matching byte or NULL if the
                                                                                                     character does not occur  in  the  given  memory area.
*
*3. char *strchr(const char *s, int c);                 locate character in string  (Forward)        return a pointer to the matched character or NULL if
                                                                                                     the character is not found.
*
*4. char *strrchr(const char *s, int c);                locate character in string  (Backward)       return a pointer to the matched character or NULL if
                                                                                                     the character is not found.
*
*5. char *strstr(const char *haystack, const char *needle);       locate a substring                 return a pointer to the beginning of the substring,
                                                                                                     or NULL if the substring is not found.
*
*6. char *strcasestr(const char *haystack, const char *needle);   locate a substring,ignores the     return a pointer to the beginning of the substring,
                                                                  case of both arguments.            or NULL if the substring is not found.
*
  • 内存及字符串拷贝、比较函数归类
*           函数名                                                  用途                                        备注
*
*1. void *memcpy(void *dest, const void *src, size_t n);        copy memory area                      The memcpy() function returns a pointer to dest.
*
*2. char *strcpy(char *dest, const char *src);                  copy a string                         return a pointer to the destination string dest.
*
*3. char *strncpy(char *dest, const char *src, size_t n);       copy a string                         return a pointer to the destination string dest.
*
*4. void *memmove(void *dest, const void *src, size_t n);       copy memory area , may overlap        returns a pointer to dest.
*
*5. int memcmp(const void *s1, const void *s2, size_t n);       compare memory areas                  returns an integer less than, equal to, or greater than zero if the first n bytes of s1 is found
*
*6. int strcmp(const char *s1, const char *s2);                 compare two strings                   return an integer less than, equal to, or greater than zero if s1 is foundfound
*
*7. int strncmp(const char *s1, const char *s2, size_t n);      compare two strings                   UP
*
*8. int strcasecmp(const char *s1, const char *s2);             compare two strings ignoring case     UP
*
*9. int strncasecmp(const char *s1, const char *s2, size_t n);  compare two strings ignoring case     UP
*
* 10. char *strdup(const char *s);                              duplicate a string                     returns a pointer to a new string which is a duplicate of the string s.  Memory for the new string is obtained with
* 
  • 内存或字符串连接、分割、求长等函数归类
*           函数名                                                  用途                                            备注
*1. char *strcat(char *dest, const char *src);                  concatenate two strings                 return a pointer to the resulting string dest
*
*2. char *strncat(char *dest, const char *src, size_t n);       UP                                      UP
*
*3. char *strtok(char *str, const char *delim);                 extract tokens from strings             第一次调用时,str必须不为空,第二次调用str必须为空
*
*4. char *strtok_r(char *str, const char *delim, char **saveptr);   可重入函数,线程安全                推荐使用这个分割函数,具体讨论见http://blog.csdn.net/liuintermilan/article/details/6283705
*

以上,就是对第一项的整理归纳。接下来,会对第二项 字符串转换  进行归纳。

时间: 2024-07-30 03:57:37

归纳整理Linux下C语言常用的库函数----内存及字符串控制及操作的相关文章

归纳整理Linux下C语言常用的库函数----文件操作

在没有IDE的时候,记住一些常用的库函数的函数名.参数.基本用法及注意事项是很有必要的. 参照Linux_C_HS.chm的目录,我大致将常用的函数分为一下几类: 1. 内存及字符串控制及操作 2. 字符串转换 3. 字符测试 4. 文件操作 5. 时间日期 6. 常用数学函数 7. 文件内容操作 8. 文件权限控制 9. 进程操作 10. 线程操作 11. Socket操作 12. 信号处理 13. 数据结构及算法 这次主要总结的是上面黑色部分,关于文件操作的函数. 系统调用归类 * * 函数

归纳整理Linux下C语言常用的库函数----时间日期数学及算法

在没有IDE的时候,记住一些常用的库函数的函数名.参数.基本用法及注意事项是很有必要的. 参照Linux_C_HS.chm的目录,我大致将常用的函数分为一下几类: 1. 内存及字符串控制及操作 2. 字符串转换 3. 字符测试 4. 文件操作 5. 时间日期 6. 常用数学函数 7. 文件内容操作 8. 文件权限控制 9. 进程操作 10. 线程操作 11. Socket操作 12. 信号处理 13. 数据结构及算法 时间函数归类 /*时间函数归类 * * 函数名 用法 备注 * *1.char

笔记整理——Linux下C语言正则表达式

Linux下C语言正则表达式使用详解 - Google Chrome (2013/5/2 16:40:37) Linux下C语言正则表达式使用详解 2012年6月6日Neal627 views发表评论阅读评论 标准的C和C++都不支持正则表达式,但有一些函数库可以辅助C/C++程序员完成这一功能,其中最著名的当数Philip Hazel的Perl-Compatible Regular Expression库,许多Linux发行版本都带有这个函数库. C语言处理正则表达式常用的函数有regcomp

LINUX下C语言编程基础

实验二 Linux下C语言编程基础 一.实验目的 1. 熟悉Linux系统下的开发环境 2. 熟悉vi的基本操作 3. 熟悉gcc编译器的基本原理 4. 熟练使用gcc编译器的常用选项 5 .熟练使用gdb调试技术 6. 熟悉makefile基本原理及语法规范 7. 掌握静态库和动态库的生成 二.实验步骤 1. 快捷键 Ubuntu中: 2. vim VIM是一个非常好的文本编辑器,很多专业程序员使用VIM编辑代码,即使以后你不编写程序,只要跟文本打交道,都应该学学VIM,可以浏览参考一下普通人

Linux下C语言的几道经典面试题

本篇文章整理了几道Linux下C语言的经典面试题,相信对大家更好的理解Linux下的C语言会有很大的帮助,欢迎大家探讨指正. 1.如果在Linux下使用GCC编译器执行下列程序,输出结果是什么? 答案如下: 2.C语言程序不使用任何条件运算符,打印出十次"Hello"? 答案如下: 或是: 3.如果在Linux下使用GCC编译器执行下列程序,输出结果是什么? 答案如下: 4.如果在Linux下使用GCC编译器执行下列程序,输出结果是什么? 答案如下: 5.如果在Linux下使用GCC编

Linux下C语言编程基础学习记录

VIM的基本使用  LINUX下C语言编程 用gcc命令编译运行C语言文件 预处理阶段:将*.c文件转化为*.i预处理过的C程序. 编译阶段:将*.i文件编译为汇编代码*.s文件. 汇编阶段:将*.s文件转化为*.o的二进制目标代码文件. 链接阶段:将*.o文件转化为可执行文件. 生成可执行文件:将*.o转换为可执行文件. 执行可执行C语言文件. gcc常用选项列表 -c      只编译不链接,生成目标文件“.o” -S      只编译不汇编,生成编码代码 -E      只进行预编译,不做

linux下C语言函数执行时间统计

转载:http://blog.csdn.net/linquidx/article/details/5916701#t5 写好程序,用gcc编译,带上-pg参数,然后运行以后分析gmon.out文件: 命令exp:   gprof ./test-main ./gmon.out >1.log  在1.log中会生成各函数运行情况. gprof 1.1 简介 gprof实际上只是一个用于读取profile结果文件的工具.gprof采用混合方法来收集程序的统计信息,他使用检测方法,在编译过程中在函数入口

Linux下提权常用小命令

有些新手朋友在拿到一个webshell后如果看到服务器是Linux或Unix操作系统的就直接放弃提权,认为Linux或Unix下的提权很难,不是大家能做的,其实Linux下的提权并没有很多人想象的那么难,你真去尝试做了,也许你就会发现Linux下的提权并不难,尤其是一些简单的提权方法是很容易学会的.Linux下的提权我知道的比较简单的方法都是在命令行下完成的,很多新手叉子可能根本没接触过Linux下的一些常用命令,今天危险漫步就给大家介绍一些Linux下提权过程中常用到的Linux命令,由于我也

LINUX下C语言编程调用其他函数、链接头文件以及库文件

LINUX下C语言编程经常需要链接其他函数,而其他函数一般都放在另外.c文件中,或者打包放在一个库文件里面,我需要在main函数中调用这些函数,主要有如下几种方法: 1.当需要调用函数的个数比较少时,可以直接在main函数中包含该文件,比如一个文件夹下包含add.c和main.c文件: 方法一: 文件add.c定义两个整数相加的函数,code如下: #include <stdio.h> #include <math.h> int add(int a,int b) { int z;