C语言文件操作 和 预编译命令
来源:互联网 发布:观看农村淘宝的感想 编辑:程序博客网 时间:2024/06/08 20:11
//read文件int main(){char *path = "D:\\friends.txt";FILE *fp = fopen(path, "r");char buff[500];while (fgets(buff,50,fp)){printf("%s\n", buff);}fclose(fp);system("pause");return 0;}//写文件int main(){char *path = "D:\\friends.txt";FILE * fp = fopen(path, "w");if (fp == NULL){printf("failed。。。。");return 0;}char * text = "我们看好你";fputs(text, fp);fclose(fp);system("pause");return 0;}//读写二进制文件int main() {char * read_path = "D:\\LogViewPro.exe";char * write_path = "D:\\LogViewPro_write.exe";//read FILE * read_fp = fopen(read_path, "rb");//writeFILE * write_fp = fopen(write_path, "wb");char buff[50];int len = 0;while ((len = fread(buff, sizeof(char), 50, read_fp)) != 0) {fwrite(buff, sizeof(char), len, write_fp);}fclose(read_fp);fclose(write_fp);system("pause");return 0;}//size of the fileint main() {char *read_path = "D:\\liuyan.png";FILE *fp = fopen(read_path, "r");if (fp == NULL){return 0;}fseek(fp, 0, SEEK_END);long filesize = ftell(fp);printf("%ld \n", filesize);system("pause");return 0;}///////////////////////////// 文本文件加解密////////////////////////void encode(char normal_path[], char encode_path[]) {FILE * normal_fp = fopen(normal_path, "r");FILE * encode_fp = fopen(encode_path, "w");int ch;while ((ch = fgetc(normal_fp)) != EOF){fputc(ch ^ 7, encode_fp);}fclose(normal_fp);fclose(encode_fp);}void decode(char encode_path[], char decode_path[]) {FILE * normal_fp = fopen(encode_path, "r");FILE * encode_fp = fopen(decode_path, "w");int ch;while ((ch = fgetc(normal_fp)) != EOF) {fputc(ch ^ 7, encode_fp);}fclose(normal_fp);fclose(encode_fp);}int main() {char * nomal_path = "D:\\friends.txt";char * encode_path = "D:\\friends_encode.txt";char * decode_path = "D:\\friends_decode.txt";encode(nomal_path, encode_path);decode(encode_path, decode_path);system("pause");return 0;}/////////////////////////////////////////二进制的加解密///////////////////////////////////////void biEncode(char normal_path[], char encode_path[], char * password) {FILE * normal_fp = fopen(normal_path, "rb");FILE * encode_fp = fopen(encode_path, "wb");int ch;int pwd_legth = strlen(password);int i = 0;while ((ch = fgetc(normal_fp)) != EOF){fputc(ch ^ password[i % pwd_legth], encode_fp);i = (i++) % 10001;}fclose(normal_fp);fclose(encode_fp);}void biDecode(char encode_path[], char decode_path[], char * password) {FILE * normal_fp = fopen(encode_path, "rb");FILE * encode_fp = fopen(decode_path, "wb");int ch;int pwd_legth = strlen(password);int i = 0;while ((ch = fgetc(normal_fp)) != EOF) {fputc(ch ^ password[i % pwd_legth], encode_fp);i = (i++) % 10001;}fclose(normal_fp);fclose(encode_fp);}int main() {char * nomal_path = "D:\\liuyan.png";char * encode_path = "D:\\liuyan_encode.png";char * decode_path = "D:\\liuyan_decode_.png";biEncode(nomal_path, encode_path, "ILoveDn");biDecode(encode_path, decode_path, "ILoveDn");//encode(nomal_path, encode_path);/*decode(encode_path, decode_path);*/system("pause");return 0;}//#define 标识符 字符串// 字符串替换// typedef 别名#define MAX(x, y) ((x) > (y)) ? x: y#define Mint main() {//#include "A.txt"for (int i = 0; i < 5; i++){printf("%d \n", i);}int max = MAX(3, 5);printf("%d \n", max);#ifdef M#ifdef Mprintf("%d \n", 110);#else printf("%d \n", 120);#endif#endif#ifndef Xprintf("%d \n", 130);#endifsystem("pause");return 0;}#define MAX(x,y) (((x)>(y))?(x):(y))#define MIN(x,y) (((x)<(y))?(x):(y))int main(void){#ifdef MAX //判断这个宏是否被定义printf("3 and 5 the max is:%d\n", MAX(3, 5));#endif#ifdef MINprintf("3 and 5 the min is:%d\n", MIN(3, 5));#endifreturn 0;}/** (1)三元运算符要比if,else效率高* (2)宏的使用一定要细心,需要把参数小心的用括号括起来,* 因为宏只是简单的文本替换,不注意,容易引起歧义错误。*/
阅读全文
0 0
- C语言文件操作 和 预编译命令
- 【C++】预编译命令
- 【C++】预编译命令
- c 预编译命令
- 【C++】预编译命令
- c语言预编译
- c语言预编译
- c语言预编译
- C语言预编译
- C语言-预编译
- 让java文件支持C语言预编译指令
- C/C++ 预编译命令
- C/C++ 预编译命令
- c语言预编译学习
- C语言的预编译
- C语言预编译指令
- C语言的预编译
- C语言 预编译 详解
- c语言创建函数时void *与 void做修饰符的区别
- 界面加载完后执行Jquery
- 关于怎么读取Maven项目resource目录下面的文件
- Android—(第三方百度地图)
- 编写自己的代码库(javascript常用实例的实现与封装)
- C语言文件操作 和 预编译命令
- css中left和margin-left的区别
- Lucene在Eclipse下的部署
- js前端实现模糊查询
- JavaScriptCore的坑? 可能,待研究(JSExportAs方式绑定的本地通信)
- Linux设备模型(7)_Class
- 日常学习之 std::pair
- WARN No appenders could be found for logger的解决方法
- 最大子矩阵和