明白了喃。呵呵~
人在江湖【走】,怎能不挨【刀】;为了能活【口】,唯有把己【超】!come on...
#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编辑过]
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
#define MAX 3
struct day
{
int month;
int day1;
};
struct mydata
{
char name[20];
struct day birthday;
char telnum[20];
};
int main(void)
{
int f1,i=0,j;
char ch;
struct mydata *a[MAX],*p;
f1=open("C:\\list.bin",O_APPEND|O_WRONLY|O_BINARY);
if((f1!=-1))
{
do
{
printf("input the name:");
gets(a[i]->name);
printf("input the birthday(day):");
scanf(" %d",a[i]->birthday.day1);
printf("input the birthday(month):");
scanf(" %d",a[i]->birthday.month);
getchar();
printf("input the telphonenumber:");
gets(a[i]->telnum);
printf("still input (press n ou N to quie)?");
scanf(" %c",&ch);
getchar();
i++;
}while((ch!=78)&&(ch!=110)&&(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;}
}
for(i=0;i<MAX;i++)
write(f1,&a[i],sizeof(a[i]));
close(f1);
printf("Data accepted!!\n");
}
else
printf("\nFile Opening Failure!!\n");
}
帮我看一下。我输入到DAY过后就出现系统错误。弹出该内存不能WRITTEN???
先建一个list.bin在C盘里哟~搞完这个再去看单内存。哈哈!
[此贴子已经被作者于2006-6-27 9:18:48编辑过]