首页上一页 1 下一页尾页 2 条记录 1/1页
学生信息管理
发表在C语言图书答疑
2012-10-25
是否精华
是
否
版块置顶:
是
否
你好 关于c语言项目案例分析那本书上191页的学生信息管理系统里面
#include<iostream.h>
#include<string.h>
#include<fstream.h>
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#define LEN sizeof(struct student)
#define FORMAT "%-8d%-15s%-30s%-30s%-30s%-30s\n"
#define DATA stu[i].num,stu[i].name,stu[i].bookname1,stu[i].bookname2,stu[i].bookname3,stu[i].bookname4
struct student
{
int num;
char name[15];
char bookname1[30];
char bookname2[30];
char bookname3[30];
char bookname4[30];
};
struct student stu[50];
void search();
void menu();
void findbname();
void findbnum();
void findbwriter();
void menu()
{
system("cls");
printf("\n\n\n");
printf("\t\t*********欢迎进入图书馆系统*********\n");
printf("\t\t\t\t\t\t0.学生登录 \n");
printf("\t\t\t\t\t图书查询:1.图书名查询 \n");
printf("\t\t\t\t\t 2.索书号查询 \n");
printf("\t\t\t\t\t 3.作者查询 \n");
printf("请选择序号(0-3):");
}
void main()
{
int n;
menu();
scanf("%d",&n);
while(n)
{switch(n)
{case 0:search();break;
case 1:findbname();break;
case 2:findbnum();break;
case 3:findbwriter();break;
default:break;
}
getch();
menu();
scanf("%d",&n);
}
}
void search()
{
FILE *fp;
char *stu;
int snum,i,m=0;
char ch[2];
if((fp=fopen("student.txt","rb"))==NULL)
{
printf("文件无法打开\n");
return;
}
while(!feof(fp))
if(fread(&stu[m],LEN,1,fp)==1)
m++;
fclose(fp);
if(m==0)
{
printf("no record!\n");
return;
}
printf("请输入学号:");
scanf("%d,&snum");
for(i=0;i<m;i++)
[font color=#FF0000] if(snum==stu[i].num)[/font]
{
printf("number name bookname1 bookname2 bookname3 bookname4\t\n");
printf(FORMAT,DATA);
break;
}
}
if(i==m)
printf("学号不存在!\n");
}
我调试上面的程序出现错误 error C2228: left of '.num' must have class/struct/union type
这是为什么呀
#include<iostream.h>
#include<string.h>
#include<fstream.h>
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#define LEN sizeof(struct student)
#define FORMAT "%-8d%-15s%-30s%-30s%-30s%-30s\n"
#define DATA stu[i].num,stu[i].name,stu[i].bookname1,stu[i].bookname2,stu[i].bookname3,stu[i].bookname4
struct student
{
int num;
char name[15];
char bookname1[30];
char bookname2[30];
char bookname3[30];
char bookname4[30];
};
struct student stu[50];
void search();
void menu();
void findbname();
void findbnum();
void findbwriter();
void menu()
{
system("cls");
printf("\n\n\n");
printf("\t\t*********欢迎进入图书馆系统*********\n");
printf("\t\t\t\t\t\t0.学生登录 \n");
printf("\t\t\t\t\t图书查询:1.图书名查询 \n");
printf("\t\t\t\t\t 2.索书号查询 \n");
printf("\t\t\t\t\t 3.作者查询 \n");
printf("请选择序号(0-3):");
}
void main()
{
int n;
menu();
scanf("%d",&n);
while(n)
{switch(n)
{case 0:search();break;
case 1:findbname();break;
case 2:findbnum();break;
case 3:findbwriter();break;
default:break;
}
getch();
menu();
scanf("%d",&n);
}
}
void search()
{
FILE *fp;
char *stu;
int snum,i,m=0;
char ch[2];
if((fp=fopen("student.txt","rb"))==NULL)
{
printf("文件无法打开\n");
return;
}
while(!feof(fp))
if(fread(&stu[m],LEN,1,fp)==1)
m++;
fclose(fp);
if(m==0)
{
printf("no record!\n");
return;
}
printf("请输入学号:");
scanf("%d,&snum");
for(i=0;i<m;i++)
[font color=#FF0000] if(snum==stu[i].num)[/font]
{
printf("number name bookname1 bookname2 bookname3 bookname4\t\n");
printf(FORMAT,DATA);
break;
}
}
if(i==m)
printf("学号不存在!\n");
}
我调试上面的程序出现错误 error C2228: left of '.num' must have class/struct/union type
这是为什么呀