The C Programming Language
你板子冒烟了
这个作者很懒,什么都没留下…
展开
-
c语言,宏相关
文章目录1,防止一个头文件被重复包含2,得到指定地址上的一个字节或字3,得到一个field在结构体(struct)中的偏移量4,使用一些宏跟踪调试5,字符串化# 和 宏连接符##6,常用语内核的填充结构相关代码7,可变参数传递1,防止一个头文件被重复包含#ifndef BODYDEF_H#define BODYDEF_H//头文件内容#endif2,得到指定地址上的一个字节或字#define MEM_B( x ) ( *( (byte *) (x) ) )#define MEM_W(原创 2021-12-01 13:23:29 · 143 阅读 · 0 评论 -
c语言表达式计算顺序
C 语言中,任何表达式的子表达式求值顺序是未指定的,编译器可能以任意顺序对这个表达式求值,而且同一表达式再度求值时可能会采用另一种顺序。C 中有运算符从左到右 / 从右到左结合性,但没有从左到右 / 从右到左求值的概念如:表达式 ( f1( ) + f2( ) + f3( ) ) ,操作符 + 具有从左到右的结合性,但在运行时对f1( ) 、f2( )、f3( ) 这 3 个函数的调用可以是任意顺序。f3( ) 可能是第一个被调用,也有可能是第二个或者第三个被调用。...原创 2020-03-28 11:18:57 · 8297 阅读 · 6 评论 -
C:16进制格式化输出
%x 对应于:unsigned int 或者 int%#x 会在16进制数前加上 0x ,%#X 会在16进制数前加上 0X下面的例程中:%8x 限定输出结果占8位,不够补空格%08x 限定输出结果占8位,不够补0#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>int main(int argc, char** argv) { i原创 2021-10-17 21:29:37 · 5351 阅读 · 0 评论 -
细谈select函数(C语言)
文章目录1、介绍2、例程例程1例程21、介绍Select在Socket编程中还是比较重要的,可是对于初学Socket的人来说都不太爱用Select写程序,他们只是习惯写诸如connect、accept、recv或recvfrom这样的阻塞程序(所谓阻塞方式block,顾名思义,就是进程或是线程执行到这些函数时必须等待某个事件的发生,如果事件没有发生,进程或线程就被阻塞,函数不能立即返回)。可是使用Select就可以完成非阻塞(所谓非阻塞方式non-block,就是进程或线程执行此函数时不必非要等待事件的转载 2021-10-09 13:22:24 · 5344 阅读 · 0 评论 -
c语言的指针长度
指针反映的一个系统的最大寻址长度。简言之就是:32位系统的指针位数位4字节,64位系统的指针位数是8字节。64位虚拟机下的例程、运行结果1、#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>int main(int argc, char** argv) { printf("sizeof(int* )=%ld\n", sizeof(in原创 2021-10-08 09:13:18 · 1800 阅读 · 0 评论 -
C:一般类型指针和数组指针对比
一个普通数据类型的变量A,一个该数据类型的指针B。指针B指向这个变量A。指针变量B的值就是变量A的地址。A的地址和B的地址是不同的#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>int main(int argc, char** argv) { int a = 6; int *b = &a; printf(原创 2021-10-07 11:25:08 · 173 阅读 · 0 评论 -
scanf 读取单个字符串时遇到空格会停止读取
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>int main(int argc, char** argv) { int a, b; char c[64] = {0}; char d[64] = {0}; char e[64] = {0}; scanf("%d %d", &a, &b);原创 2021-10-04 00:44:53 · 1672 阅读 · 0 评论 -
c实现对一个数列的全排列
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>void swap(int *a, int *b) { int tmp; tmp = *a; *a = *b; *b = tmp;}void sort(int *a, int start, int end){ int i; if(start原创 2021-10-03 14:06:49 · 166 阅读 · 0 评论 -
c中字符串常量在进程中的位置
#include<stdio.h>#include<string.h>#include<stdlib.h>#include <unistd.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <unistd.h>#define STR_1 "1122334455667788"#define STR_2原创 2021-09-23 14:07:18 · 112 阅读 · 0 评论 -
scanf格式化输入字符串中包含空格
#include<stdio.h>#include<string.h>#include<stdlib.h>#include <unistd.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <unistd.h>int main(int argc, char** argv){ char a[66];原创 2021-09-15 13:34:17 · 1090 阅读 · 0 评论 -
time_t,tm结构体,以及与string之间的转换函数
#include <stdio.h>#include <string.h>#include <unistd.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <time.h>int main(int argc, char** argv){ // typedef long time_t time_t原创 2021-09-06 15:57:11 · 499 阅读 · 0 评论 -
网络地址相关结构体,函数
1、字节序:多字节数据在内存中数据内字节存储顺序,或者是在网络中数据内字节的传输顺序。分为:主机字节序和网络字节序(网络字节序定死为大端格式)大端:高字节低地址2、主机字节序,网络字节序转换函数htonl:host to network long (32bit),将32bit的数据从 主机字节序 转换为 网络字节序ntohl:network to host long (32bit),将32bit的数据从 网络字节序 转换为 主机字节序htons:host to network short (1原创 2021-08-17 20:28:59 · 296 阅读 · 0 评论 -
snprintf,strncpy 和 strncat
sprintf头文件#include<stdio.h>函数原型int sprintf(char *str, const char *format, ...);功能:将一个格式化的字符串输出到指定的字符串 str 。返回值:返回的是源串 / 格式串 的长度(strlen,不包括结尾的 ‘ \0 ’ )特点:1、是一个变参函数,函数原型中括号里面三个点表示可以接任意多个参数,这些参数与格式串 format 内部的格式说明符一一对应。2、printf 是将原创 2020-11-17 21:48:07 · 1201 阅读 · 5 评论 -
----getopt()函数
----getopt()函数。英雄不问出处,getopt()函数的出处就是unistd.h头文件(哈哈),写代码的时候千万不要忘记把他老人家include上。再来看一下这家伙的原型:int getopt(int argc,char * const argv[ ],const char * optstring);前两个参数大家不会陌生,没错,就是老大main函数的两个参数!老大传进来的参数自然要有人接着!第三个参数是个字符串,看名字,我们可以叫他选项字符串(后面会说明)返回值为int类型,我们都知原创 2020-06-30 14:34:29 · 207 阅读 · 0 评论 -
C中只定义指针不赋值是不会给这个指针分配内存的*
#include<stdio.h>#include<stdlib.h>#include<malloc.h>int tst_func(char **a){ *a = (char *)malloc(6); if(!(*a)) { printf("%d:-------malloc fail---------.\r\n", __LINE__); return -1; }}int main(int ar原创 2021-03-19 11:23:29 · 1586 阅读 · 2 评论 -
extern不能用于声明数据类型,只能用来声明函数或者具体的变量
extern不能用于声明 数据类型,只能用来声明函数或者具体的变量下列代码编译报错#include<stdio.h>#include<stdlib.h>#include<string.h> extern struct mm; int main(int argc, char** argv){ struct mm a = { .a = 6, .b = 36, }; retur原创 2021-03-24 11:58:01 · 415 阅读 · 0 评论 -
c 函数体外只能定义变量,不能赋值
struct data ttst[2];(ttst[0]).name = "name0";(ttst[0]).value = "value0";(ttst[1]).name = "name1";(ttst[1]).value = "value1";以上写在函数体外了其实c函数提体外只能定义变量,不能赋值除非在定义的时候完成赋值法1struct data ttst[2] ={ {"name0", "value0"}, {"name1", "value1"},原创 2021-03-20 20:37:37 · 1214 阅读 · 0 评论