第11课 [第五周 1]
#include <cstdio>
void test_file() {
FILE *fp;
fp = fopen("file1", "w");
if (fp != NULL) {
int x = 101;
fprintf(fp, "%d\n", x);
fprintf(fp, "%d\n", x + 100);
fprintf(fp, "%d\n", &x);
fclose(fp);
} else {
printf("create file error");
}
}
提供了“r
”、“w
”、“a
”、“+
”、“b
”、“t
”六种模式选择符号:
- r 以只读方式打开文件;该文件必须存在
- w 以只写文件打开文件;若文件存在则先文件清空;若文件不存在则建立该文件
- a 以附加的方式打开只写文件;若文件不存在,则会建立该文件;如果文件存在,写入的数据会被加到文件尾,即文件原先的内容会被保留。(EOF符保留)
+
可读写- b 二进制文件
- t 文本文件
共有如下组合方式:
r
w
a
r+
w+
a+
rb
wb
ab
rb+
wb+
ab+
第12课 [第五周 2]
- 链表
struct student {
int id;
char *name;
char *house;
student *next;
};
typedef struct {
int id;
char *name;
char *house;
} student2;
typedef struct node {
int n;
struct node *next;
} node;
-
队列
-
栈
第13课 [第七周 1]
- typedef
//
// Created by morningcat on 2021/2/14.
//
//#include <cstdint>
//#include <cstdio>
#include <stdio.h>
#include <stdint.h>
#include "test13.h"
void test_13() {
int8_t a1 = 128; // -128~127
uint8_t b1 = 256; // 0~255
u_int8_t c1 = 256; // 0~255
printf("int8_t=%d\n", a1);
printf("uint8_t=%d\n", b1);
int16_t a2 = 32767; // -32768 ~ 32767
uint16_t b2 = 65535; // 0~65535
printf("int16_t=%d\n", a2);
printf("uint16_t=%d\n", b2);
int32_t a3 = 2147483647; // -2147483648 ~ 2147483647
uint32_t b3 = 4294967295; // 0~4294967295
printf("int32_t=%ld\n", a3);
printf("uint32_t=%ld\n", b3);
int64_t a4 = 9223372036854775807; // -9223372036854775808 ~ 9223372036854775807
uint64_t b4 = 9223372036854775808; // ???
printf("int64_t=%lld\n", a4);
printf("uint64_t=%lld\n", b4);
}
#define FORMAT "2^%2d = %22lld\n"
void test_13_2(int n) {
if (n < 1) { return; }
int d = 2;
unsigned long long rs = 1;
for (int i = 1; i < n; ++i) {
rs = rs * d;
printf(FORMAT, i, rs);
}
rs = (rs - 1) * 2 + 1;
printf(FORMAT, n, rs);
}
-
PNG 位图
一款较好的检测程序内存问题的工具
valgrind -v --leak-check=full a.out
- 位运算
<<
&