#include <stdio.h>
#include <conio.h>
#include <string.h>
#define ESC 27
#define MAX 3
struct day
{
int month;
int day1;
};
struct mydata
{
char name[20];
struct day birthday;
char telnum[14];
};
int main(void)
{
FILE *fptr1;
struct mydata a[MAX];
char ch,*p;
int i=0;
fptr1=fopen("c:\\tongxun.txt","a");
if((fptr1!=NULL))
{
printf("Input the date:\n");
do
{
printf("input the name:");
gets(a[i].name);
printf("\ninput the month:");
scanf("%d",&a[i].birthday.month);
printf("\ninput the day:");
scanf("%d",&a[i].birthday.day1);
printf("\ninput the telephone number:");
scanf("%s",&a[i].telnum);
i++;
printf("continue?(press ESC to quit)\n");
getchar();
}while(ch=getche()!=ESC && (i<MAX));
for(i=0;i<MAX-1;i++)
{if(strcmp(a[i].name,a[i+1].name)>0)
{p=a[i]; a[i]=a[i+1]; a[i+1]=p; }}//这一行!错误:incompatible types in assignment???(貌似是p和a不是同一类数据,不能交换?)
fwrite(a,sizeof(a),1,fptr1);
fclose(fptr1);
printf("\nFile append successful!!\n");
}
else
printf("File Opening Failure!!\n");
return 0;
}
C-FREE编译器。。。急死了喃。。。这么一天连个添加都没写完。。。
而且不加上排列这段,TYPE出来有乱码。为何?
[此贴子已经被作者于2006-6-26 16:08:26编辑过]