Code:
#include<stdio.h>
#define max 20
#define max1 50
typedef struct phoneaddress{
	char name[20];
	char tell[11];
	char email[25];
}phoneaddress;
struct stack{
	phoneaddress data;
	struct stack *link;
	};
//khai trien stack
struct stack *push(struct stack *p, phoneaddress value)
{
   	struct stack *temp;
   	temp=(struct stack *)malloc(sizeof(struct stack));
	if(temp==NULL) 
	 {
     		 printf("No Memory available Error\n");
      		 exit(0);
	}
	temp->data=value;
   	/*temp->data.name = value.name;
   	temp->data.tell = value.tell;
   	temp->data.email = value.email;*/
   	temp->link = p;
   	p = temp;
   return(p);
}
struct stack *pop(struct stack *p,phoneaddress *val)
{
	struct stack *temp;
	if(p==NULL)
	return 0;
	else
	{
		*val=p->data;
		/*(*val).name=p->data.name;
		(*val).tell=p->data.tell;
		(*val).email=p->data.email;*/
		temp=p;
		p=p->link;
		free(temp);
		return p;
	}
}
////////////////////////////////////////////////////////////
int main (void){
	FILE* fp,*fp1;
	phoneaddress db[max],db1[max];
	int i,n,m;
	phoneaddress val;
	struct stack *top1=NULL;
	//tao file chua du lieu danh ba......................
	printf("nhap vao bao nhieu contact:");
	scanf("%d",&n);
	for(i=0;i<n;i++){
		printf("name:");scanf("%s",db[i].name);
		printf("sdt:");scanf("%s",db[i].tell);
		printf("email:");scanf("%s",db[i].email);
	}
	if((fp=fopen("danhba.dat","w+b"))==NULL){
		printf("khong mo duoc file.");
		return 0;
	}
	fwrite(db,sizeof(phoneaddress),n,fp);
	fclose(fp);
//push du lieu tu file vao stack...................
	fread(db,sizeof(phoneaddress),n,fp);
	for(i=0;i<n;i++){
	push(top1,db[i]);
	}
	fclose(fp);
	//ghi du lieu vao file thong qua stack...........
	if((fp1=fopen("danhba1.dat","w+b"))==NULL){
		printf("khong mo dc file.");
		return 1;
	}
	while(top1!=NULL){
	pop(top1,&val);
	fwrite(&val,sizeof(phoneaddress),1,fp1);
	}
	//////////////////////////////////////
	printf("doc du lieu tu file moi.\n");
	fread(db1,sizeof(phoneaddress),n,fp1);
	for(i=0;i<n;i++){
		printf("%s\t",db1[i].name);
		printf("%s\t",db1[i].tell);
		printf("%s\n",db1[i].email);
		printf("---------------------------------\n");
}
fclose(fp1);
getch();
}
mình sai chỗ nào giúp mình với.
code chạy được nhưng khi thực hiên thao tác in data từ file mới thì gặp lỗi
mình nghĩ do phần code đỏ,nhưng hok biết sửa ntn.
có thể nói rõ cho mình hoạt động của hàm fwrite được không.