C语言基础
C语言基础
追寻远方的人
你的职责是平整土地,而非焦虑时光。
展开
-
day11 C语言 随机读写
C语言 随机读写 ftell #include<stdio.h> #include<stdlib.h> #include<string.h> int main (void) { FILE *fp; if((fp = fopen("hello.txt","w")) == NULL) { printf("打开文件失败!\n"); exit(EXIT_FAILURE); } printf("%ld\n原创 2021-01-22 16:13:37 · 95 阅读 · 0 评论 -
day10 C语言 顺序读写
C语言 顺序读写 fputs fgets #include<stdio.h> #include<stdlib.h> #define MAX 1024 int main (void) { FILE *fp; char buffer[MAX]; if((fp = fopen("lines.txt","w")) == NULL) { printf("打开文件失败!\n"); exit(EXIT_FAILURE);原创 2021-01-22 16:12:50 · 134 阅读 · 0 评论 -
day09 C语言 位域 位运算符
C语言 位域 #include<stdio.h> #include<stdlib.h> #include<time.h> int main (void) { struct Test { unsigned int a:1; unsigned int b:1; unsigned int c:2; //不能超过32 }; struct Test test; test.a原创 2021-01-22 09:32:16 · 100 阅读 · 1 评论 -
day08 c语言 枚举类型
C语言 枚举类型 #include<stdio.h> #include<stdlib.h> #include<time.h> int main (void) { enum Week {sun, mon,tue, wed, thu, fri, sat}; enum Week today; struct tm *p; time_t t ; time(&t); p = localtime(&t); t原创 2021-01-21 21:29:39 · 60 阅读 · 0 评论 -
day07 c语言 typedef
c语言 typedef 基础typedef #include<stdio.h> #include<stdlib.h> typedef int INTEGER,*PTRINT; //相比起宏定义的直接替换,typedef是对类型的封装 int main(void) { INTEGER a = 520 ; PTRINT b,c; b = &a; c = b; printf("addr of a = %p\n",c); return原创 2021-01-21 20:55:01 · 70 阅读 · 0 评论 -
day06 c语言 单链表查找
c语言 单链表 单链表查找 #include<stdio.h> #include<stdlib.h> struct Book { char title[128]; char author[40]; struct Book *next; }; void get(struct Book *book) { printf("请输入书名:\n"); scanf("%s",book->title); printf("请输入作者:\n");原创 2021-01-21 13:08:27 · 144 阅读 · 0 评论 -
day05 c语言 单链表插入
c语言 单链表插入 首插法 #include<stdio.h> #include<stdlib.h> struct Book { char title[128]; char author[40]; struct Book *next; }; void get(struct Book *book) { printf("请输入书名:\n"); scanf("%s",book->title); printf("请输入作者:\n")原创 2021-01-21 13:07:44 · 126 阅读 · 0 评论 -
day04 c语言 结构体
c语言 结构体 结构体指针 #include <stdio.h> #include <stdlib.h> #include <string.h> struct Date { int year; int month; int day; }; struct Book { char title[128]; char author[40]; float price; struct Date date; char pu原创 2021-01-20 22:42:58 · 74 阅读 · 0 评论 -
day03 c语言 高级宏定义
c 语言 高级宏定义 undef标签 #include <stdio.h> #include <stdlib.h> #include <string.h> #define PI 3.14 int main() { int r; float s; printf("请输入半径:\n"); scanf("%d",&r); #undef PI //显示错误 s = PI * r * r; //printf("面积为原创 2021-01-20 18:01:03 · 74 阅读 · 0 评论 -
day02 c语言 动态分配
c语言 动态分配 malloc #include <stdio.h> #include <stdlib.h> int main() { int *ptr = NULL; ptr =(int*) malloc(sizeof(int)); if(ptr == NULL) { printf("分配内存失败!\n"); exit(1); } printf("请输入一个整数:\n"); scanf("%d原创 2021-01-20 13:49:40 · 120 阅读 · 0 评论 -
day01 c语言 递归
c语言 递归 汉诺塔 #include <stdio.h> #include <stdlib.h> void hanoi(int n, char x, char y, char z) { if( n == 1) { printf("%c --> %c\n", x, z); } else { hanoi(n-1, x, z, y); printf("%c --> %c\n",x, z)原创 2021-01-20 10:53:44 · 67 阅读 · 0 评论