error C2106: '=' : left operand must be l-value之类的问题求解!谢谢
#include<stdio.h> #include<string.h>
#include<windows.h>
struct student
{
char name[20];
char adress[20],phone[20];
int yb;
}stu[3];
void output();
void add();
void find();
void del();
void change();
int main()
{
int i,j=1,k;
printf("\n\n******************欢 迎 光 临 学 生 通 讯 录 管 理 系 统 *********************\n\n\n");
printf(" 1.输出通讯录\n\n");
printf(" 2.删除记录\n\n");
printf(" 3.查找记录\n\n");
printf(" 4.修改记录\n\n");
printf(" 5.添加新联系人\n\n");
printf(" 6.退出程序\n\n\n");
printf("*****************************************************************\n\n");
while(j!=0)
{
printf("请输入序号:");
scanf("%d",&i);
if(i==1)
output();
if(i==2)
del();
if(i==3)
find();
if(i==4)
change();
if(i==5)
add();
if(i==6)
break;
printf("\n\n\n您是否要继续使用学生通讯录管理系统?输入“0”结束程序,非0继续:\n\n\n");
scanf("%d",&j);
if(j!=0)
{
printf("\n\n******************欢迎光临学生通讯录管理系统*********************\n\n\n");
printf(" 1.输出通讯录\n\n");
printf(" 2.删除记录 \n\n");
printf(" 3.查找记录\n\n");
printf(" 4.修改记录\n\n");
printf(" 5.添加新联系人\n\n");
printf(" 6.退出程序\n\n\n");
printf("*****************************************************************\n\n");
}
}
getchar();
return 0;
}
void add()
{
FILE*fp;
int i=1,j,k;
char ch,str[20];
if((fp=fopen("1.txt","ab+"))==NULL)
{
fp=fopen("1.txt","wb+");
while(i!=0)
{
printf("请输入姓名:\n");
scanf("%s",stu[0].name);
printf("请输入地址:\n");
scanf("%s",stu[0].adress);
printf("请输入邮编:\n");
scanf("%d",&stu[0].yb);
getchar();
printf("请输入电话号码:\n");
scanf("%s",stu[0].phone);
fwrite(&stu[0],sizeof(struct student),1,fp);
printf("信息已经输入成功输入数据库,是否继续输入??\n 按数字“0”退出,非“0”继续");
scanf("%d", &i);
}
}
else
{
fclose(fp);
fp=fopen("1.txt","ab+");
i=1;
while(i!=0)
{
printf("请输入姓名:\n");
scanf("%s",stu[0].name);
printf("请输入地址:\n");
scanf("%s",stu[0].adress);
printf("请输入邮编:\n");
scanf("%d",&stu[0].yb);
getchar();
printf("请输入电话号码:\n");
scanf("%s",stu[0].phone);
fwrite(&stu[0],sizeof(struct student),1,fp);
printf("信息已经输入成功输入数据库,是否继续输入??\n 按数字“0”退出,非“0”继续");
scanf("%d", &i);
}
}
fclose(fp);
}
void output()
{
FILE*fp;
char ch;
int i=1;
if((fp=fopen("1.txt","rb"))==NULL)
{
printf("目前数据库中还没有任何数据!!\n\n");
exit(0);
}
printf(" **************************************************************\n\n\n");
read(&stu[0],sizeof(struct student),1,fp);
while(!feof(fp))
{
printf(" 姓名:%-8s 地址:%-10s 邮编:%-8d 电话号码:%-8s\n\n",stu[0].name,stu[0].adress,stu[0].yb,stu[0].phone);
fread(&stu[0],sizeof(struct student),1,fp);
}
printf("\n\n *************************************************************\n\n");
fclose(fp);
}
void find()
{
FILE*fp;
char name[20][20];
int i=0,j=1,m=0;
if((fp=fopen("1.txt","rb"))==NULL)
{
printf("目前数据库中还没有任何数据!!\n\n");
exit(0);
}
while(j!=0)
{
fp=fopen("1.txt","rb");
printf("\n\n输入你想查询的姓名:");
scanf("%s",name[m]);
fread(&stu[0],sizeof(struct student),1,fp);
while(!feof(fp))
{
if(strcmp(stu[0].name,name[m])==0)
{
i++;
printf(" **************************************************************\n\n\n");
printf(" 姓名:%-8s 地址:%-10s 邮编:%-8d 电话号码:%-8s\n\n",stu[0].name,stu[0].adress,stu[0].yb,stu[0].phone);
printf("\n\n\n *************************************************************\n\n");
}
fread(&stu[0],sizeof(struct student),1,fp);
}
if(i==0)
printf("\n\n不好意思,没有找到您的数据!O(∩_∩)O\n\n");
i=0;
printf("是否要继续查询?按“0”退出,非0继续\n\n");
scanf("%d",&j);
m++;
}
fclose(fp);
}
void del()
{
FILE*fp1,*fp2;
char name[20][20];
int i=0,j=1,k=1,m=0;
if((fp1=fopen("1.txt","rb"))==NULL)
{ printf("目前数据库中还没有任何数据!!\n\n");
exit(0);
}
while(j!=0)
{
fp1=fopen("1.txt","rb");
printf("\n\n输入你想删除信息的人的姓名:");
scanf("%s",name[m]);
fread(&stu[0],sizeof(struct student),1,fp1);
while(!feof(fp1))
{
if(strcmp(stu[0].name,name[m])==0)
{
i++;
printf("\n\n 姓名:%-8s 地址:%-10s 邮编:%-8d 电话号码:%-8s\n\n",stu[0].name,stu[0].adress,stu[0].yb,stu[0].phone);
printf("以上为您要查询的信息,确认删除吗?按“0”键确认,非0取消");
scanf("%d",&k);
break;
}
fread(&stu[0],sizeof(struct student),1,fp1);
}
if(i==0)
printf("\n\n不好意思,没有找到您的数据!O(∩_∩)O\n\n");
if(k==0)
{
fclose(fp1);
fp1=fopen("1.txt","rb");
fp2=fopen("2.txt","wb+");
fread(&stu[0],sizeof(struct student),1,fp1);
if(strcmp(stu[0].name,name[m])==0)
{
fread(&stu[0],sizeof(struct student),1,fp1);
while(!feof(fp1))
{
fwrite(&stu[0],sizeof(struct student),1,fp2);
fread(&stu[0],sizeof(struct student),1,fp1);
}
}
else
{
while(!feof(fp1))
{
fwrite(&stu[0],sizeof(struct student),1,fp2);
fread(&stu[0],sizeof(struct student),1,fp1);
if(strcmp(stu[0].name,name[m])==0)
{
fread(&stu[0],sizeof(struct student),1,fp1);
}
}
}
fclose(fp1);
fp1=fopen("1.txt","wb+");
rewind(fp2);
fread(&stu[0],sizeof(struct student),1,fp2);
while(!feof(fp2))
{
fwrite(&stu[0],sizeof(struct student),1,fp1);
fread(&stu[0],sizeof(struct student),1,fp2);
}
fclose(fp1);
fclose(fp2);
DeleteFile("2.txt");
}
fclose(fp1);
printf("是否要继续删除?按“0”退出,非0继续\n\n");
scanf("%d",&j);
i=0;
m++;
}
fclose(fp1);
}
void change()
{
FILE*fp1,*fp2;
char name[20][20],newname[20][20],newadress[20][20];
int i=0,j=1,k=1,num,newyb,m=0; char newphone[20][20];
if((fp1=fopen("1.txt","rb"))==NULL)
{
printf("目前数据库中还没有任何数据!!\n\n");
exit(0);
}
while(j!=0)
{
fp1=fopen("1.txt","rb");
printf("\n\n输入你想修改信息的人的姓名:");
scanf("%s",name[m]);
fread(&stu[0],sizeof(struct student),1,fp1);
while(!feof(fp1))
{
if(strcmp(stu[0].name,name[m])==0)
{
i++;
printf("%s %s %d %s\n",stu[0].name,stu[0].adress,stu[0].yb,stu[0].phone);
printf("\n\n以上为您要修改的信息,确认修改吗?按“0”键确认修改,非0取消\n\n");
scanf("%d",&k);
}
fread(&stu[0],sizeof(struct student),1,fp1);
}
if(i==0)
printf("\n\n不好意思,没有找到您的数据!O(∩_∩)O\n\n");
if(k==0)
{
fclose(fp1);
fp1=fopen("1.txt","rb");
fp2=fopen("2.txt","wb+");
fread(&stu[0],sizeof(struct student),1,fp1);
if(strcmp(stu[0].name,name[m])==0)
{
stu[1].name=stu[0].name;
stu[1].adress=stu[0].adress;
stu[1].phone=stu[0].phone;
stu[1].yb=stu[0].yb;
fread(&stu[0],sizeof(struct student),1,fp1);
while(!feof(fp1))
{
fwrite(&stu[0],sizeof(struct student),1,fp2);
fread(&stu[0],sizeof(struct student),1,fp1);
}
}
else
{
while(!feof(fp1))
{
fwrite(&stu[0],sizeof(struct student),1,fp2);
fread(&stu[0],sizeof(struct student),1,fp1);
if(strcmp(stu[0].name,name[m])==0)
{
stu[1].name=stu[0].name;
stu[1].adress=stu[0].adress;
stu[1].phone=stu[0].phone;
stu[1].yb=stu[0].yb;
fread(&stu[0],sizeof(struct student),1,fp1);
}
}
}
fclose(fp1);
fp1=fopen("1.txt","wb+");
rewind(fp2);
fread(&stu[0],sizeof(struct student),1,fp2);
while(!feof(fp2))
{
fwrite(&stu[0],sizeof(struct student),1,fp1);
fread(&stu[0],sizeof(struct student),1,fp2);
}
fclose(fp1);
fclose(fp2);
DeleteFile("2.txt");
fp1=fopen("1.txt","ab");
printf("输入你想要改变的项目:\n ");
lable: printf("1.更改姓名 2.更改住址 3.更改邮编 4.更改联系方式");
scanf("%d",&num);
switch(num)
{ case 1: printf("请输入新的姓名:");
scanf("%s",newname[m]);
stu[1].name=newname[m];
fwrite(&stu[1],sizeof(struct student),1,fp1);
fclose(fp1);
break;
case 2:
printf("请输入新的住址:");
scanf("%s",newadress[m]);
stu[1].adress=newadress[m];
fwrite(&stu[1],sizeof(struct student),1,fp1);
fclose(fp1);
break;
case 3:
printf("请输入新的邮编:");
scanf("%d",&newyb);
stu[1].yb=newyb;
fwrite(&stu[1],sizeof(struct student),1,fp1);
fclose(fp1);
break;
case 4:
printf("请输入新的联系方式:");
scanf("%s",newphone[m]);
stu[1].phone=newphone[m];
fwrite(&stu[1],sizeof(struct student),1,fp1);
fclose(fp1);
break;
default:
printf("请正确输入!!");
fclose(fp1);
goto lable;
}
}
printf("是否要继续修改人员信息?按“0”退出,非0继续\n\n");
scanf("%d",&j);
i=0;
m++;
}
}
D:\14263728\tongxunlu.cpp(17) : warning C4101: 'k' : unreferenced local variable
D:\14263728\tongxunlu.cpp(68) : warning C4101: 'str' : unreferenced local variable
D:\14263728\tongxunlu.cpp(68) : warning C4101: 'ch' : unreferenced local variable
D:\14263728\tongxunlu.cpp(67) : warning C4101: 'j' : unreferenced local variable
D:\14263728\tongxunlu.cpp(67) : warning C4101: 'k' : unreferenced local variable
D:\14263728\tongxunlu.cpp(122) : error C2065: 'read' : undeclared identifier
D:\14263728\tongxunlu.cpp(282) : error C2106: '=' : left operand must be l-value
D:\14263728\tongxunlu.cpp(283) : error C2106: '=' : left operand must be l-value
D:\14263728\tongxunlu.cpp(284) : error C2106: '=' : left operand must be l-value
D:\14263728\tongxunlu.cpp(301) : error C2106: '=' : left operand must be l-value
D:\14263728\tongxunlu.cpp(302) : error C2106: '=' : left operand must be l-value
D:\14263728\tongxunlu.cpp(303) : error C2106: '=' : left operand must be l-value
D:\14263728\tongxunlu.cpp(328) : error C2106: '=' : left operand must be l-value
D:\14263728\tongxunlu.cpp(335) : error C2106: '=' : left operand must be l-value
D:\14263728\tongxunlu.cpp(349) : error C2106: '=' : left operand must be l-value
Error executing cl.exe.
tongxunlu.exe - 10 error(s), 5 warning(s)
错误应该怎么改!求大侠给出正确答案!谢谢!