如何排错呢
#include<stdio.h>#include<stdlib.h>
#include<string.h>
#include<malloc.h>
#define STUDENT "E:\C语言程序\student.txt"
typedef struct xxx{
int group;
int id;
char passwd[6];
char name[20];
char sex[6];
float score[6];
struct xxx *next;
}stu;
stu *head, *load, *sear, *inser, *del, *tamp;
FILE *STU;
void password(void);
stu* loading(void);
void insert(void);
void search(void);
void datadelete(void);
void manu(void);
void password(void)
{
stu * s;
char q[6],p[6];
int l;
if((s = (stu *)malloc(sizeof(stu))) == NULL)
{
printf("不能分配内存空间!");
exit(0);
}
s = loading();
for(l = 0; l < 3; l++)
{
printf("请输入新密码:");
scanf("%s", q);
printf("请再一次输入新密码:");
scanf("%s", p);
if(strcmp(q,p) == 0)
{
strcpy(s->passwd,p);
fwrite(s, sizeof(stu), 1, STU);
printf("修改成功!\n");
break;
}
else
password();
}
if(l == 2)
{printf("请重新登录!");loading();}
free(s);
}
void datadelete(void)
{
int k;
if((head = (stu *)malloc(sizeof(stu))) == NULL)
{
printf("不能分配内存空间!");
exit(0);
}
if((tamp = (stu *)malloc(sizeof(stu))) == NULL)
{
printf("不能分配内存空间!");
exit(0);
}
if((del = (stu *)malloc(sizeof(stu))) == NULL)
{
printf("不能分配内存空间!");
exit(0);
}
printf("请输入需要被删除用户的用户名:");
scanf("%s",del->name);
fread(tamp,sizeof(stu), 1, STU);
head = tamp;
for(k = 0; k < 2; k++)
{
while(head == NULL)
{
if(strcmp(del->name,head->name) == 0)
{
head = NULL;
do
{
fwrite(head,sizeof(stu),1,STU);
head = head->next;
fread(tamp,sizeof(stu), 1, STU);
head = tamp;
}while(head == NULL);
}
else
{
head = head->next;
fread(tamp,sizeof(stu), 1, STU);
head = tamp;
}
}
}
if(k == 1)
{
printf("用户已经不存在\n");
manu();
}
free(head);
free(tamp);
free(del);
}
void search(void)
{
int j, i;
if((head = (stu *)malloc(sizeof(stu))) == NULL)
{
printf("不能分配内存空间!");
exit(0);
}
if((tamp = (stu *)malloc(sizeof(stu))) == NULL)
{
printf("不能分配内存空间!");
exit(0);
}
if((sear = (stu *)malloc(sizeof(stu))) == NULL)
{
printf("不能分配内存空间!");
exit(0);
}
printf("请输入用户名");
scanf("%s",sear->name);
fread(tamp,sizeof(stu), 1, STU);
head = tamp;
for(j = 0; j < 2; j++)
{
while(head == NULL)
{
if(strcmp(sear->name, head->name) == 0)
{
printf("%d\t%d\t%s\t%s\t%s\n",&inser->group, &inser->id, inser->passwd, inser->name, inser->sex);
for(i = 0; i < 6; i++)
{
printf("%f\t", inser->score[i]);
}
break;
}
else
{
head = head->next;
fread(tamp,sizeof(stu), 1, STU);
head = tamp;
}
}
search();
}
if(i == 1)
{
printf("用户不存在\n");
manu();
}
free(head);
free(tamp);
free(sear);
}
stu* loading(void)
{
int flg, n;
if((head = (stu *)malloc(sizeof(stu))) == NULL)
{
printf("不能分配内存空间!");
exit(0);
}
if((tamp = (stu *)malloc(sizeof(stu))) == NULL)
{
printf("不能分配内存空间!");
exit(0);
}
if((load = (stu *)malloc(sizeof(stu))) == NULL)
{
printf("不能分配内存空间!");
exit(0);
}
printf("用户登录名:");
scanf("%s",load->name);
fread(tamp, sizeof(stu), 1, STU);
head = tamp;
for(flg = 0; flg < 3; flg++)
{
while(strcmp(load->name,head->name ) == 0)
{
head = head->next;
fread(tamp, sizeof(stu), 1, STU);
head = tamp;
}
printf("用户登录密码:");
scanf("%s",load->passwd);
if(strcmp(load->passwd, head->passwd) == 0)
{ printf("登录成功!\n");
printf("%d\t%d\t%s\t%s\t%s\n",&head->group, &head->id, head->passwd, head->name, head->sex);
for(n = 0; n < 6; n++)
printf("%f\t", head->score[n]);
return head;
}
else
{printf("请重新登录!\n");loading(); return NULL;}
}
free(head);
free(tamp);
free(load);
manu();
}
void insert(void)
{
int i,flag = 0;
if((inser = (stu *)malloc(sizeof(stu))) == NULL)
{
printf("不能分配内存空间!");
exit(0);
}
printf("Please input group, id, password, name and sex, ',' to divide!\n");
scanf("%d,%d,%s,%s,%s",&inser->group,&inser->group,inser->passwd,inser->name,inser->sex);
printf("please input score for six course\n");
for(i = 0; i < 6; i++)
{
printf("the %d course:",i + 1);
scanf("%f",&inser->score.[i]);
}
printf("%d\t%d\t%s\t%s\t%s\n",&inser->use, &inser->id, inser->passwd, inser->name, inser->sex);
for(i = 0; i < 6; i++)
{
printf("%f\t", inser->score[i]);
}
printf("Please enter any but 0 to ensure:\n ");
scanf("%d",flag);
if(flag)
{
fwrite(inser, sizeof(stu), 1, STU);
inser = inser->next;
}
else
insert();
free(inser);
}
void manu(void)
{
stu *p;
int select = 0;
if((p = (stu *)malloc(sizeof(stu))) == NULL)
{
printf("不能分配内存空间!");
exit(0);
}
while(1)
{
printf("===================================================================\n");
printf("1 load\t2 insert\t3 search\t4 delete\t5 password\t6 exit\n");
printf("===================================================================\n");
scanf("%d", &select);
switch(select)
{
case 1:
loading();manu();break;
case 2:
{
p = loading();
if(p->group == 1)
{insert();manu();}
else
{ printf("你没有该权限!\n"); manu();}
break;
}
case 3:
search();manu();break;
case 4:
datadelete();manu();break;
case 5:
password();manu();break;
case 6:
exit(0);break;
default:
printf("Please select again!\n");manu();
}
}
}
void main(void)
{
STU = fopen(STUDENT, " a+b ");
if((head = (stu *)malloc(sizeof(stu))) == NULL)
{
printf("不能分配内存空间!");
exit(0);
}
head = NULL;
if(STU == NULL)
{
printf("Open ERROR\n");
exit(1);
}
if(ftell(STU) == 0)
{
insert();
}
else
manu();
fclose(STU);
}
E:\C语言程序\Administritor.cpp(223) : error C2059: syntax error : '['
E:\C语言程序\Administritor.cpp(225) : error C2228: left of '.printf' must have class/struct/union type
E:\C语言程序\Administritor.cpp(225) : error C2227: left of '->use' must point to class/struct/union
E:\C语言程序\Administritor.cpp(225) : error C2227: left of '->id' must point to class/struct/union
E:\C语言程序\Administritor.cpp(225) : error C2227: left of '->passwd' must point to class/struct/union
E:\C语言程序\Administritor.cpp(225) : error C2227: left of '->name' must point to class/struct/union
E:\C语言程序\Administritor.cpp(225) : error C2227: left of '->sex' must point to class/struct/union
E:\C语言程序\Administritor.cpp(228) : error C2227: left of '->score' must point to class/struct/union
E:\C语言程序\Administritor.cpp(235) : error C2227: left of '->next' must point to class/struct/union
E:\C语言程序\Administritor.cpp(284) : warning C4129: 'C' : unrecognized character escape sequence
E:\C语言程序\Administritor.cpp(284) : warning C4129: 's' : unrecognized character escape sequence