预处理器指令

1.#define指令定义了一个标识符及一个字符序列(即字符集合)。在源程序中每次遇到该标识符时,就用定义的字符序列替换它。标识符被称为宏名,替换过程称为宏替换,指令的一般形式为: #define macro-name char-sequence 2.#error指令强迫编译器停止编译,它主要用于程序调试。#error指令的一般形式为: #error error-message 3.#if, #else, #elif, #endif #if e...
2014-01-30 09:46 | 阅读 1349 次 | 评论 0 条

fread()和fwrite()用法

#include <stdio.h> #include <stdlib.h> int main() { FILE *fp; double d = 12.23; int i = 101; long l = 123023L; if((fp = fopen("test", "wb")) == NULL) { printf("Cannot open file.\n"); exit(1); } fwrite(&amp;d, sizeof(double), 1, fp); fwrite(&amp;i, sizeof(int), 1, fp); fwrite(&a...
2014-01-30 08:54 | 阅读 1762 次 | 评论 0 条

fseek()函数用法

#include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { FILE *fp; if(argc != 3) { printf("Usage: SEEK filename byte\n"); exit(1); } if((fp = fopen(argv[1], "rb")) == NULL) { printf("Cannot open file.\n"); exit(1); } if(fseek(fp, atol(argv[2]), SEEK_SET)) { pri...
2014-01-30 08:46 | 阅读 1251 次 | 评论 0 条