#include<stdio.h>
#include<string.h>
#include<malloc.h>
struct info
{
char xuehao[15];
char xingming[20];
char xingbie[5];
char qq[10];
char phone[13];
char e_mail[30];
char messege[50];
};
void main()
{
struct info *pointor;
FILE *fp;
char change[10];
char flag='N';
char filename[50];
void getinfo(struct info *);
void printinfo(struct info*);
void input(char *buffer);
FILE *creat(char *);
void save(struct info*,int size,int count,FILE *fp);
void read(struct info*pointor,int size,int count,FILE *fp);
/*******************************************************************/
printf("Enter the file name:\n");
input(filename);
fp=creat(filename);
printf("Enter data:\n");
do
{
pointor=(struct info*)malloc(sizeof(struct info));
getinfo(pointor);
save(pointor,sizeof(struct info),1,fp);
printf("continue?(YES\\NO)\n");
input(change);
if(strcmp("yes",change)==0)
flag='Y';
else
flag='N';
}
while(flag=='Y');
/******************************************************************/
printf("to open file:\n");
printf("Enter the filename:\n");
input(filename);
fp=fopen(filename,"r");
do
{
read(pointor,sizeof(struct info),1,fp);
printinfo(pointor);
printf("continue:(yes\\no)\n");
input(change);
if(strcmp("yes",change)==0)
flag='Y';
else
flag='N';
}
while(flag=='Y');
/*****************************************************************/
}
void getinfo(struct info *pointor)
{
printf("xuehao:");
input(pointor->xuehao);
printf("xingming:");
input(pointor->xingming);
printf("xingbie:");
input(pointor->xingbie);
printf("qq:");
input(pointor->qq);
printf("phone:");
input(pointor->phone);
printf("e-mail:");
input(pointor->e_mail);
printf("messege:");
input(pointor->messege);
}
void printinfo(struct info *pointor)
{
printf("xuehao:");
printf("%s\n",pointor->xuehao);
printf("xingming:");
printf("%s\n",pointor->xingming);
printf("xingbie:");
printf("%s\n",pointor->xingbie);
printf("qq:");
printf("%s\n",pointor->qq);
printf("phone:");
printf("%s\n",pointor->phone);
printf("e-mail:");
printf("%s\n",pointor->e_mail);
printf("messege:");
printf("%s\n",pointor->messege);
}
void input(char *buffer)
{
char c;
char *p;
p=buffer;
c=getchar();
while(c!='\n')
{
*p=c;
p++;
c=getchar();
}
*p='\0';
}
FILE *creat(char *filename)
{
FILE *fp;
fp=fopen(filename,"w");
if(fp!=NULL)
printf("creat ok!\n");
else
printf("creat error!\n");
return fp;
}
void save(struct info*pointor,int size,int count,FILE *fp)
{
fwrite(pointor,size,count,fp);
printf("save ok!\n");
}
void read(struct info*pointor,int size,int count,FILE *fp)
{
fread(pointor,size,count,fp);
printf("read ok!\n");
}
----------------解决方案--------------------------------------------------------
用TC2.0 编译的
----------------解决方案--------------------------------------------------------
你写的这个程序,关CPU什么事?
函数的声明要写在main外面
----------------解决方案--------------------------------------------------------
编译成功了
除了有2个警告
但是无法执行
还有有谁告诉我一下
为什么会有警告出现呀
谢!
----------------解决方案--------------------------------------------------------
那你看一下撒
----------------解决方案--------------------------------------------------------
没有警告啊~~正常的
----------------解决方案--------------------------------------------------------
我用dev-c++编译的,除了把main函数改为int外,都是好的。运行也是对的啊。
LZ可以试一下。
----------------解决方案--------------------------------------------------------