typedef struct int level C unsigned flags char Slides: 38 Download presentation 文件指针 typedef struct { int level; C的标准库函数每 unsigned flags; 操作一个文件,都 char 为这个文件建立一 fd; unsigned char 个FILE型变量。 hold; int bsize; unsigned char _FAR * buffer; unsigned char _FAR * 有了这个FILE型变量,C库函数就将文件底层操作的 curp; 细节与程序员隔离开,使文件操作的程序更容易编写 unsigned istemp; 7 short 文件的读写需要调用相关标准库函数 fscanf, fprintf fgets, fputs fgetc, fputc fread, fwrite 16 文件的读写 int a=100; float f=3. 1; FILE *fp; printf ("a=%d, f=%f", a, f); //输出a和f的 值 fp=fopen(“m. dat", "wb"); //创建m. dat文 件 if(fp!=NULL) { //将变量a和f的值写入到文件中 fprintf (fp, "a=%d, f=%f", a, f); fclose(fp); //关闭该文件 } 20 文件的读写 fread和fwrite函数的原型是: unsigned fread(void *ptr, unsigned size, unsigned n, FILE *stream); unsigned fwrite(void *ptr, unsigned size, unsigned n, FILE*stream); 28 文件的读写 下面的程序先将一个int型数组存放到文件中, 然后再读出来: #include <stdio. h> void main() { int a[10]={10, 20, 30, 40, 50, 60, 70, 80, 90, 100}; int k; FILE *fp 1, *fp 2; fp 1=fopen("yang. dat", "wb"); //创建二进制文件 yang. dat 30 先将100个整数写入到一个文件中,然后从文件中 读取第 50个整数的值。 #include <stdio. h> void main() { int a; FILE *fp 1, *fp 2; fp 1=fopen("integer. dat", "wb"); if(fp 1==NULL) { printf("can't create integer. datn"); for(a=1; a<=100; a++) fwrite(&a, sizeof(int), 1, fp 1); fclose(fp 1); fp 2=fopen("integer. dat", "rb"); fseek(fp 2, 49*sizeof(int), SEEK_SET); fread(&a, sizeof(int), 1, fp 2); fclose(fp 2); printf("the 50 th data is %dn", a); } return; } 38 Typedef struct tree int info struct *leftTypedef struct tree int info struct *leftInt treeTypedef int elementSum0Typedef struct tree int infoStruct node *nextTypedef struct nodeStruct node int data struct node* nextInt argc char argvInt main int argc char argvPublic void drawsquare(int x, int y, int len)Public int divide(int a int b)Int max(int x int y)Interface calculator public int add class testTypedef struct in c linked listTypedef struct nodeTypedef in structureTypedef struct cTypedef struct#include Typedef struct unionTypedef listTypedef struct tagNodenextChars = [0] * 128AsciiUnsigned short intType modifierUnsigned charCopying a struct in cSigned vs unsigned intUnsigned int longDouble charUnsigned representationWarningStruct in cStruct student char *nameStruct student char *name