
C语言函数
Kato33
这个作者很懒,什么都没留下…
展开
-
isascii()
#include <ctype.h>int isascii(int c);描述checks whether c is a 7-bit unsigned char value that fits into the ASCII character set.检查参数c是否为ASCII 码字符,也就是判断c 的范围是否在0 到127 之间。返回值The values returned are nonzero if the character c falls into the tested原创 2021-03-04 16:59:18 · 281 阅读 · 1 评论 -
signal函数
信号与signal函数????简介#include <signal.h>void (*signal(int sig, void (*func)(int)))(int);/* 信号注册函数 为了在产生信号时调用,返回之前注册的函数指针*/上述函数的返回值类型为函数指针,因此函数声明有些繁琐。我们将上述函数声明整理如下:1️⃣ 函数名:signal2️⃣ 参数:int sig, void (*func)(int)3️⃣ 返回类型:参数为int型,返回void型函数指针调用原创 2021-02-12 19:24:47 · 576 阅读 · 0 评论 -
getopt()函数
???? 为什么会记录这个函数,因为这个函数还蛮有趣的,主要是我之前想实现下ping程序,需要用到这个函数。该函数的作用是解析命令行参数#include <unistd.h>int getopt(int argc, char * const argv[], const char *optstring);extern char *optarg;extern int optind, opterr, optopt;描述函数的作用是:解析命令行参数。它的参数argc和argv是程序调用时原创 2021-02-11 23:27:09 · 454 阅读 · 0 评论 -
getuid()函数
使用这个函数可以获取运行某个进程(程序)的用户的uid。Linux系统使用一个专门的文件来将用户的登录名匹配到对应的UID值,我们可以使用命令 sudo nvim /etc/passwd 进行查看,包含了一些与用户相关的信息。root:x:0:0::/root:/bin/bashkato:x:1000:1000:kato:/home/kato:/usr/bin/zsh其实这个文件有很多条信息,我只单独列出这两条。很清晰的看到每条信息由7个字段组成,由:隔开。字段包含如下信息:1️⃣ 登录用户名原创 2021-02-11 15:24:21 · 5543 阅读 · 0 评论 -
学习inet_ntoa()函数
#include <sys/socket.h> // 这个好像在这里可以省略#include <netinet/in.h> // 提供struct in_addr#include <arpa/inet.h> // 提供inet_ntoa()char *inet_ntoa(struct in_addr in);DESCRIPTIONThe inet_ntoa() function converts the Internet host address in原创 2021-02-11 13:25:08 · 9442 阅读 · 0 评论 -
配合例子理解gethostbyname()
???? 学了忘,忘了学,学了还得忘,忘了还得学,做个笔记先利用域名获取IP地址#include <netdb.h>struct hostent *gethostbyname(const char *name);struct hostent { char *h_name; /* official name of host */ char **h_aliases; /* alias list */ int h_addrtype;原创 2021-02-11 03:08:10 · 307 阅读 · 0 评论 -
gethostname函数
这里我将使用一个例子来进行方便记忆// gethostname()#include <unistd.h>int gethostname(char *name, size_t namelen);描述:函数的作用是:返回当前机器的标准主机名。namelen参数应指定name参数所指向的数组的大小。返回的名称应以null结尾,但如果namelen的长度不足以容纳主机名,则返回的名称应被截断,并且未指定返回的名称是否以null结尾。返回值:成功时返回0;否则返回-1。例子:getho原创 2021-02-11 02:14:48 · 3912 阅读 · 0 评论 -
perror函数例子
#include <stdio.h>void perror( const char *str );/* perror()函数打印str(字符串)和一个相应的执行定义的错误消息到全局变量errno中. */例子:perror.c#include <stdio.h>#include <stdlib.h>int main(void){ FILE *fp; fp = fopen("file.txt", "r"); if (fp == NULL)原创 2021-02-11 01:53:48 · 189 阅读 · 0 评论