test_fwite.c
资源名称:C数据结构课程设计.rar [点击查看]
上传用户:janny_wxd
上传日期:2010-02-03
资源大小:261k
文件大小:1k
源码类别:
控制台编程
开发平台:
C/C++
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- #define SIZE 3
- #define MAX 13
- #define OK 1
- #define TRUE 1
- #define FALSE 0
- #define ERROR 0
- #define OVERFLOW -2
- #define OPSETSIZE 7
- #define STACK_INIF_SIZE 50
- #define STACKINCREMENT 10
- #define PR printf
- #define SIZE 3
- FILE *fp_airline,*fp_customer;
- struct customer{
- char name[9];//顾客名
- char line_num[8];//航班号
- int seat_num;//座位号
- // struct customer *next;//下一个结点
- }cus[3];
- void main()
- {
- // customer cus[3];
- int i=0;
- char filename[50]="c:\customer.dat";
- char *name[3]={"欧阳锦林","尹焕亮","付胜"};
- char *line_num[3]={"bjnc01","bjsh02","shgz03"};
- int seat_num[3]={1,5,10};
- for (i=0;i<3;i++){
- strcpy(cus[i].name , name[i]);
- strcpy(cus[i].line_num , line_num[i]);
- cus[i].seat_num =seat_num[i];
- // cus[i].next=NULL;
- }
- if((fp_customer=fopen("filename","wb+"))==NULL)
- {
- printf("can not open file to write:%sn",filename);
- }
- for (i=0;i<3;i++){
- if(fwrite(&cus[i],sizeof(struct customer),1,fp_customer)!=1)
- {
- PR("customer_dat write errorn");
- fclose(fp_customer);
- }
- }
- fclose(fp_customer);
- }