#include<malloc.h>
#define N 10
int main(void)
{
int i,j,x,m,flag=1
char ch
m=N
char (*p)[10]=(char (*)[10])calloc(N,10*sizeof(char))
for(i=0i<10i++)
for(j=0j<10j++)
p[i][j]='\0'
printf("输入ID时不超过10位,第一位不能为'*'\n")
i=0
while(1)
{
while(i<m)
{
printf("请输入第%d名的ID:",i+1)
ch=getchar()
for(j=0j<10j++)
{
if(j==0&&ch=='*')
{
flag=0
break
}
if(ch=='\n')
break
p[i][j]=ch
ch=getchar()
}
if(flag==0)
break
i=i+1
}
if(flag==0)
break
m=m+N
p=(char (*)[10])realloc(p,m*10*sizeof(char))
for(x=ix<mx++)
for(j=0j<10j++)
p[x][j]='\0'
}
for(j=0j<ij++)
{
printf("第%d名:",j+1)
printf("%s\n",p[j])
}
free(p)
return 0
}
代码: #include"stdio.h"#include"stdlib.h"
#include"conio.h"
#include"string.h"
#include"io.h"
#define ESC 27
#define ENTER 13
#define Y 89
#define y 121
#define N 78
#define n 110
void vmenu1()
char choose()
void password()
char *getps()
void mimam()
void build()
void save()
void buy()
void open1()
void modify()
void modifyM()
void XnumM()
void XclassM()
void XnameM()
void add()
void xuehaoA()
void xingmingA()
void query()
void xuehaoQ()
void xingmingQ()
void delete1()
void xuehaoD()
void xingmingD()
void sort()
void sortX()
void sortN()
void sortA()
void all()
void help()
void lock()
void exit1()
struct record
{
char cnumber[15]
char cclass[15]
char cname[15]
char cmoney[10]
char cspend[10]
struct record *next
}
struct sot
{
char ccnumber[15]
struct sot *pnext
}
struct address
{
char *adss
struct address *anext
}
struct sot *chead=NULL
struct record *head=NULL,*ppointer=NULL,*temp
struct record *modf
struct address *ahead=NULL
FILE *fp
int Fflag=0
int counts=0
int loop=0
void main()
{
char menu
password()
while(loop==0)
{
system("CLS")
vmenu1()
menu=choose()
switch(menu)
{
case '1':build()break
case '2':count++
if(count==1)
{
buy()
break
}
else
{
chead=NULL
buy()
break
}
case '3':open1()break
case '4':modify()k=0break
case '6':query()break
case '7':delete1()break
case '9':all()break
case 'b':help()break
case 'c':lock()break
case 'd':{loop=1exit1()break}
default:
printf("----------------------------请输入菜单上的序号 ------------------------\n")
printf("---------------------------按任意键重新开始选择 -----------------------\n")
fflush(stdin)
a=getch()
}
}
}
void password()
{
char password[15]
char *password1
char *password2
char p1[15]
char p2[15]
char a
int i
int count=0
if(access("c:\\mima.txt",00)!=0)
{
while(1)
{
system("CLS")
for(i=0i<5i++)
printf("\n")
printf("\t\t欢迎使用学生打饭系统!\n\n")
printf("\n")
printf("\n----------------------------请创建管理员密码:--------------------------------\n")
password1=getps()
for(i=0i<15i++)
p1[i]=*(password1++)
printf("\n")
printf("\n----------------------------请再输入一次密码:--------------------------------\n")
password2=getps()
for(i=0i<15i++)
p2[i]=*(password2++)
if(!strcmp(p1,p2))
{
if((fp=fopen("c:\\mima.txt","w"))==NULL)
{
printf("错误!\n")
exit(0)
}
else
{
fprintf(fp,"%s",p1)
printf("\n密码创建完毕!\n")
fclose(fp)
system("cmd.exe /c attrib c:\\mima.txt +h")
break
}
}
else
{
printf("两次输入不一致,请重新输入密码:\n")
}
}
}
else
{
while(1)
{
count++
for(i=0i<5i++)
printf("\n")
printf("----------------------------请输入管理员密码:----------------------------------\n")
password1=getps()
for(i=0i<15i++)
p1[i]=*(password1++)
if((fp=fopen("c:\\mima.txt","r"))==NULL)
{
printf("错误!\n")
exit(0)
}
else
{
fscanf(fp,"%s",password)
fclose(fp)
if(!strcmp(p1,password))
break
else
printf("\n密码错误!\n")
}
if(count<=9)
{
printf("\n您还有%d次机会。。。。。。\n",10-count)
printf("\n\n\n-------------------请按除ESC外的任意按键重新输入密码!----------------------\n")
a=getch()
if(a==ESC)
exit(0)
}
if(count==10)
{
printf("\n\n您无权使用本系统!\n")
printf("按任意键退出。。。。。。\n")
fflush(stdin)
a=getch()
exit(0)
}
}
}
printf("\n\n\n是否要对密码进行修改?\n")
printf("\t按Y或y更改,其余按键进入系统。\n")
fflush(stdin)
a=getchar()
if(a==Y||a==y)
{
mimam()
}
system("CLS")
for(i=0i<5i++)
printf("\n")
printf("\t\t欢迎使用学生打饭系统!\n\n")
printf(" ")
printf("\t\t按任意键进入系统。。。。。。\n\n")
a=getch()
}
char *getps()
{
char p[15]
password=p
while(1)
{
fflush(stdin)
*password=getch()
if(*password==ENTER)
{
break
}
putchar('*')
password++
}
*password='\0'
password=p
return(password)
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)