user-0 提问: 200悬赏，关于加fread的问题，文件读取问题

回复:
user: user-1
content: 不要把 fopen("...","...");fscanf,fprintf,fgets,fgetc,fclose //读时把\r\n替换成\n，写时把\n替换成\r\n;读到\x1a就设置EOF;读写的内容当字符看待 和 fopen("...","...b");fseek,fread,fwrite,fgetc,fclose  //不作以上替换，遇到\x1a仍继续读;读写的内容当字节看待 弄混了

user: user-2
content: 我是来读程序的，  学C不满二个月不敢帮你解答问题，帮你围观

user: user-3
content: 楼上现基友！！

user: user-4
content: #include iloveyou #define M(X) main(x) #define st  { #define ed } #define p(xx)  printf(xx); #define xx "love\n" #define iloveyou <stdio.h> M(x) st p(xx) ed

user: user-5
content: #include <stdio.h> #include <stdlib.h> #include <string.h>  typedef struct _person {     char name[20];     int number;     char question[20];     char fang_an[20];     long int ban_ji;     char di_dian[20];     int time;  }person;  typedef struct _addr_book {     person per;     struct _addr_book* next; }addr_book;   void add(addr_book *head);  void show(addr_book *head);  void search_1(addr_book *head);  void search_2(addr_book *head); void delet(addr_book *head); void save(addr_book *head); addr_book *load(addr_book *head, char *filename); void quit(addr_book *head); int print_menu(); addr_book *get_last(addr_book *from); void print_person(person *p); void input_person(person *p); char menu[]= 	"+****************************************************************+\n" 	"|                        欢迎使用教师答疑备忘录                  |\n" 	"+----------------------------------------------------------------+\n" 	"|                          1. 添加答疑信息                       |\n" 	"|                          2. 答疑时间排序                       |\n" 	"|                          3. 按照姓名查找                       |\n" 	"|                          4. 按照学号查找                       |\n"  	"|                          5. 删除信息                           |\n" 	"|                          6. 保存统计至文件                     |\n" 	"|                          7. 从文件导入统计                     |\n" 	"|                          8. 退出备忘录                         |\n" 	"+****************************************************************+\n";  int main() { 	addr_book *head = NULL; 	char filename[30];     while (1) {         switch(print_menu()) { 		case 1:	add(head); break; 		case 2:	show(head);	break; 		case 3:	search_1(head);	break; 		case 4:	search_2(head);	break; 		case 5:	delet(head); break; 		case 6:	save(head);	break; 		case 7:	printf("输入导入文件名："); 			    scanf("%s", filename); 			    head = load(head, filename); break; 		case 8:	quit(head);	break;         }     }     return 0; }   void add(addr_book *head) {     char input;     addr_book *last = NULL;     addr_book *new_addr = (addr_book*)malloc(sizeof(addr_book));      new_addr->next = NULL;     if(head == NULL)         head = new_addr;     else {         last = get_last(head);         last->next = new_addr;      }     input_person(&(new_addr->per));     printf("Y继续，N返回菜单");     getchar();     input = toupper(getchar());     if(input == 'Y') 	    add(head); 	return; }   void search_1(addr_book *head) {     int count = 0;     char input = 'N';     char name[20] = {0};     addr_book *p = head;     printf("请输入要查找的学生名字");     scanf("%s", name);     while(p != NULL) {         if(strcmp(p->per.name, name) == 0) {             print_person(&(p->per)); 			count++;         }         p = p->next;     }      if(count == 0)         printf("没有这名学生");          printf("Y继续查找，N返回菜单");     getchar();     input = toupper(getchar());     if(input=='Y')         search_1(head); 	return; }   void search_2(addr_book *head) {     int count = 0;     char input = 'N';     int num = 0;     addr_book *p = head;     printf("请输入要查找的学号");     scanf("%d", &num);      while(p != NULL) {         if(num == (p->per.number)) {  			print_person(&(p->per)); 			count++;         }         p = p->next;     }     if(count == 0) 		printf("没有这个学号");     printf("Y继续查找，N返回菜单\n");     getchar();     input = getchar();     if (input=='Y'||input=='y')         search_2(head);     }   void show(addr_book *head) {            	char w;     int count = 0;     struct tong_ji *p1 = NULL;     char question[20] = {0}; 	addr_book *p; 	addr_book *q, *r; 	addr_book* new_addr = (addr_book*)malloc(sizeof(addr_book)); 	new_addr->next = head; 	p = new_addr;     q = new_addr->next; 	p->next = NULL; 	while(q) { 		r = q->next; 		while(p->next != NULL && p->next->per.time <= q->per.time) 			p = p->next; 		q->next = p->next; 		p->next = q; 		q = r; 		p = new_addr; 	}     p = head;     printf( "会按照时间的先后来显示\n");      printf("你想要查询的问题\n");     scanf("%s", question);     while(p != NULL) {		 		if(strcmp(p->per.question, question) == 0) 			printf("%s,%d,%s,%s,%d,%s,%d\n",p->per.name,p->per.number,p->per.question,p->per.fang_an,p->per.ban_ji,p->per.di_dian,p->per.time); 		p = p->next;         }  	printf("Y继续查找，N返回菜单\n"); 	getchar();     w = getchar();     if (w=='Y'||w=='y')         show(head);  }    void delet(addr_book *head) { 	int count = 0; 	char input = 'N'; 	char name[20] = {0}; 	addr_book *p = head; 	addr_book *p1 = NULL; 	printf("请输入要删除的学生姓名"); 	scanf("%s", name); 	while (p != NULL) { 		if (strcmp(p->per.name, name) == 0) { 			print_person(&(p->per)); 			count++; 			break; 		} 		p = p->next; 	} 	if (count==0) 		printf("没有姓名为%s的学生",name); 	else { 		printf("确定要删除?Y确认，N取消");  		getchar();         input = toupper(getchar());         if(input=='Y') {             if(p == head) 				head = p->next; 			else { 				p1 = head; 				while(p1 != NULL) { 					if(p1->next == p) { 						p1->next = p->next; 						break; 					} 				} 				p1 = p1->next;             }         }         free(p); 	} 	printf("继续删除其他信息吗？Y继续删除，N返回菜单"); 	getchar(); 	input=toupper(getchar()); 	if (input=='Y') 		delet(head); 	return; }    void save(addr_book *head) { 	FILE *fp; 	char file[100]; 	addr_book *p = head; 	printf("请输入文件名:"); 	scanf("%s", file); 	fp=fopen(file, "wb"); 	while(p != NULL) { 		fwrite(p, sizeof(addr_book), 1, fp); 		p = p->next; 	} 	fclose(fp); 	printf("保存成功！\n按任意键返回\n"); 	getchar(); 	return; }   addr_book *load(addr_book *head, char *filename){ 	FILE *fp;  	addr_book *new_addr; 	addr_book *last; 	fp=fopen(filename, "rb"); 	if(fp == NULL){ 		printf("打不开文件！\n"); 		exit(0); 	} 	new_addr = (addr_book*)malloc(sizeof(addr_book));  	while(fread(&new_addr, sizeof(addr_book), 1, fp) == 1){ 		new_addr->next = NULL; 		if(head == NULL) 		    head = new_addr; 		else { 			last = get_last(head); 			last->next = new_addr;  		} 		new_addr = (addr_book *)malloc(sizeof(addr_book)); 	} 	fclose(fp);     return head; }   void quit(addr_book *head) { 	addr_book *pdel = head; 	addr_book *p = NULL; 	if (pdel == NULL) 		exit(0); 	/*如果pdel的next指针不为空，表示有下一条数据*/ 	/*先将p指向pdel，释放掉pdel，再将p重复给pdel*/ 	while(pdel->next != NULL) { 		p = pdel->next; 		free(pdel); 		pdel = p; 	}  	free(pdel);/*如果pdel的next指针为空，表示没有下一条数据，直接删除该节点*/; 	exit(0);  }   int print_menu() { 	int selected = 0; 	system("cls"); 	printf("%s", menu); 	printf(">请输入[1~8]:"); 	scanf("%d", &selected); 	getchar(); 	if (selected<1||selected>7) { 		printf("错误的选择！(请输入1~7）.按任意键继续..."); 		getchar(); 	} 	return selected; }   void input_person(person* p) {     printf("请输入答疑信息!\n");     printf("请输入学生姓名:");  scanf("%s", p->name);     printf("请输入学生学号:");  scanf("%d",&(p->number));     printf("请输入学生问题:");  scanf("%s",p->question);     printf("请输入解决方案:");  scanf("%s",p->fang_an);     printf("请输入学生班级:");  scanf("%d",&(p->ban_ji));     printf("请输入答疑地点:");  scanf("%s",p->di_dian);     printf("请输入答疑时间:");  scanf("%d",&(p->time)); 	return; }  void print_person(person* p) { 	printf("学生姓名:%s\t学生学号:%d\t学生问题:%s\t解决方案:%s\t学生班级:%d\t答疑地点:%s\t答疑时间:%d\t\n", 		p->name,p->number,p->question,p->fang_an,p->ban_ji,p->di_dian,p->time); 	return; }   addr_book *get_last(addr_book *from) { 	addr_book *p = from; 	while (p->next != NULL) 		p = p->next; 	return p; }

user: user-6
content: 把你邮箱给我  我发你

user: user-7
content: fread用法:  #include <stdio.h> #include <stdlib.h> #include <memory.h>   int main() { 	int fLen; 	char *data; 	FILE *fr = fopen("F:\\b.txt","r"); 	if(fr) 	{ 		fseek(fr,0L,SEEK_END); 		fLen = ftell(fr); 		fseek(fr,0L,SEEK_SET);	 		data = (char*)malloc(fLen); //动态申请空间 		memset(data,0,sizeof(char)*fLen); 		fread(data,fLen,1,fr); 		printf("%s\n\n", data); 	} 	else 		printf("Open file failed!\n");  	free(data); 	fclose(fr); 	 	return 0; }

user: user-8
content: 用追加方式打开

user: user-0
content: 是100，不好意思，说错了