Lecture 23 _4/5_Kailu Song
Review for exam 2,students could ask question 1.read file FILE *fptr;
fptr = fopen(filename,"rb");
int a;
double b;
fread(&a,sizeof(int),1,fptr);
fread(&b,sizeof(double),1,fptr);
Person P;
fread(&P,sizeof(Person),1,fptr);
int arr[10];
fread(arr,sizeof(int),10,fptr);
int ch;
ch = fgetc(fptr);
char = oneline[256];
fets(oneline,256,fptr);
(stop at '\n', or reach the limit'\o');
int a,b;
fscanf(fptr,"%d %d", &a,&b);
strlen not include '\o';
strcpy,strstr,strcat;
2.linklist with n nodes sorted,insert one more value
3, three outcomes:1.file;2.structure;3.dynamic structure(linked list);
========================================
Shiyu Wang Lec23 April 8th
Review for Exam2
randon access
arr[5]
arr[29]
FILE* fptr;
fptr = fopen(filename,"rb");
(binary)
int a;
double b;
fread(&a,sizeof(int),1 fptr);
fread(&b,sizeof(double),1,fptr);
int ch;
ch=fgetc(fptr);
char oneline[256];
fgets(oneline,256,fptr);
(it will stop at'\n'
or reach the limit'\0')
How to use strcpy, strstr, strcat
=======
Kevin Tan(0023987592), section#2 notes 04/05
random access
arr[5]; arr[9];
FILE *fp= NULL; fp = fopen(filename,"rb");
int a; double b; fread(&a,sizeof(int),1,fp); fread(&b,sizeof(double),1,fp); . . fscanf(fp,"%d%d",&a,&b);
Wudi Zhou, Professor Lu's section, April 9th
Exam 2 covers: File I/O, Structure, Dynamic Structure,recursive
FILE * fptr; fptr = fopen(filename,"rb"); int a; double b; fread(&a, sizeof(int),1,fptr); fread(&b,sizeof(double),1,fptr);
fptr = fopen(filename,"b"); ch = fgetc(fptr); char oneline[256]; gets(oneline,256,fptr);
fscanf(fptr,"%d", &a);/*return 1 if successful*/ fscanf(fptr,"%d",&a, &b); /*return 2 if both successful*/
Person P; fread(&p, sizeof(person),1,fptr); int arr[10]; fread(arr,sizeof(int),10,fptr); fwrite(&p,sizeof(person),1,fptr);