www.pudn.com > 模拟二级文件系统.rar > FILESYS.C


#include 
struct file{ 
 char filename[8]; 
 char content[256]; 
}file[3]={{"",},{"",},{"",}}; 
struct users{ 
 char username[8]; 
 char password[8]; 
 struct file *f; 
}users[3]={{"",},{"",},{"",}}; 
char Uname[8],Upass[8],Fname[8],con,con1,con2,con3,choice,choice1,choice2,filerw[20]; 
 
void newu(){char x;int k,d; 
again:printf("All Users Are:\n"); 
      for(k=0;k<3;k++) 
      printf("User %d Is:%s\n",k,users[k].username); 
loopu:printf("Please Input New Username(<8 Characters):\n"); 
      scanf("%s",Uname); 
	  getchar(); 
      for(k=0;k<3;k++){ 
	  if(strcmp(users[k].username,Uname)==0){ 
	  printf("This User Already Exists!Input Again:\n");goto again;} 
	  else if(strcmp(users[k].username,"")==0){ 
	  strcpy(users[k].username,Uname); 
      printf("Please Input New Userpassword(<8 Characters):\n"); 
      scanf("%s",Upass); 
	  getchar(); 
	  strcpy(users[k].password,Upass); 
	  printf("User %s And Password Have Created!\n",Uname); 
	  printf("After Created,All Users Are:\n"); 
      for(d=0;d<3;d++) 
      printf("User %d Is:%s\n",d,users[d].username); 
	  goto next;} 
	  } 
	  printf("User List Is Full!Creating User Failed!\n");goto next; 
next: printf("Again/Next(A/N)?\n"); 
chox: x=getchar(); 
	  if(x=='\n') goto chox; 
	  getchar(); 
	  if((x=='a')||(x=='A')) goto loopu; 
} 
 
void openu(){char x;int k; 
again:printf("All Users Are:\n"); 
      for(k=0;k<3;k++) 
      printf("User%d Is %s\n",k,users[k].username); 
      printf("Please Input Username:\n"); 
      scanf("%s",Uname); 
	  getchar(); 
      for(k=0;k<3;k++){ 
	  if(strcmp(users[k].username,Uname)==0){ 
	  printf("Please Input Userpassword:\n"); 
      scanf("%s",Upass); 
	  getchar(); 
	  if(strcmp(users[k].password,Upass)==0){ 
	  printf("Password Right!You Have Chosen User:%s\n",Uname);goto next1;} 
	  else {printf("Password Error!Input Again:\n");goto again;} 
	  } 
      if(k==3){printf("This User Didn't Exist!Input Again:\n");goto again;} 
	  } 
next: printf("Again/Next(A/N)?\n"); 
chox: x=getchar(); 
	  if(x=='\n') goto chox; 
	  getchar(); 
	  if((x=='a')||(x=='A')) goto again; 
next1:; 
} 
 
void queryu(){int k; 
getchar(); 
printf("All Users Are:\n"); 
for(k=0;k<3;k++) 
printf("User %d Is:%s\n",k,users[k].username); 
printf("\n"); 
} 
 
void deleteu(){char x;int k,d; 
again:printf("All Users Are:\n"); 
      for(k=0;k<3;k++) 
      printf("User %d Is %s\n",k,users[k].username); 
      printf("Please Input Username:\n"); 
      scanf("%s",Uname); 
      getchar(); 
      for(k=0;k<3;k++){ 
      if(strcmp(users[k].username,Uname)==0){ 
 	  printf("Please Input Userpassword:\n"); 
      scanf("%s",Upass); 
	  getchar(); 
	   if(strcmp(users[k].password,Upass)==0);{ 
	   strcpy(users[k].username,""); 
       printf("You Have Delete User:%s\n",Uname); 
	   printf("After Delete,All Users Are:\n"); 
       for(d=0;d<3;d++) 
       printf("User %d Is %s\n",d,users[d].username); 
       goto next;} 
       printf("Password Error!You Can't Delete This User!Input Again:\n");goto again; 
	  } 
	  } 
      if(k=3){printf("This User Didn't Exist!Input Again:\n");goto again;} 
next: printf("Again/Next(A/N)?\n"); 
chox: x=getchar(); 
	  if(x=='\n') goto chox; 
	  getchar(); 
	  if((x=='a')||(x=='A')) goto again; 
} 
 
void newf(){char x;int k,d; 
again:printf("All File Are:\n"); 
      for(k=0;k<3;k++) 
      printf("File %d Is:%s\n",k,file[k].filename); 
loopf:printf("Please Input New Filename:\n"); 
      scanf("%s",Fname); 
	  getchar(); 
      for(k=0;k<3;k++){ 
	  if(strcmp(file[k].filename,Fname)==0){ 
	  printf("This File Already Exists!Input Again:\n");goto again;} 
	  else if(strcmp(file[k].filename,"")==0){ 
	  strcpy(file[k].filename,Fname); 
	  printf("File %s Have Created!\n",Fname); 
	  printf("After Created,All Files Are:\n"); 
      for(d=0;d<3;d++) 
      printf("File %d Is:%s\n",d,file[d].filename); 
	  goto next;} 
	  } 
	  printf("User List Is Full!Creating User Failed!\n");goto next; 
next: printf("Again/Next(A/N)?\n"); 
chox: x=getchar(); 
	  if(x=='\n') goto chox; 
	  getchar(); 
	  if((x=='a')||(x=='A')) goto loopf; 
} 
 
void openf(){char x;int k; 
again:printf("All Files Are:\n"); 
      for(k=0;k<3;k++) 
      printf("File %d Is:%s\n",k,file[k].filename); 
      printf("Please Input Filename:\n"); 
      scanf("%s",Fname); 
	  getchar(); 
      for(k=0;k<3;k++){ 
	  if(strcmp(file[k].filename,Fname)==0) 
	  {printf("You Have Chosen File:%s\n",Fname);goto next1;} 
	  if(k==3){printf("This File Didn't Exist!Input Again:\n");goto again;} 
	  } 
next: printf("Again/Next(A/N)?\n"); 
chox: x=getchar(); 
	  if(x=='\n') goto chox; 
	  getchar(); 
	  if((x=='a')||(x=='A')) goto again; 
next1:; 
} 
 
void query(){int k; 
getchar(); 
printf("All Files Are:\n"); 
for(k=0;k<3;k++) 
printf("File %d Is:%s\n",k,file[k].filename); 
printf("\n"); 
} 
 
void deletef(){char x;int k; 
again:printf("All Files Are:\n"); 
      for(k=0;k<3;k++) 
      printf("File %d Is %s\n",k,file[k].filename); 
      printf("Please Input Filename:\n"); 
      scanf("%s",Fname); 
	  getchar(); 
	  for(k=0;k<3;k++){ 
	  if(strcmp(file[k].filename,Fname)==0) 
	  {strcpy(file[k].filename,""); 
	  printf("You Have Delete File:%s\n",Fname); 
	  goto next;} 
	  } 
      if(k=3){printf("This File Didn't Exist!Input Again:\n"); 
	  goto again;} 
next: printf("Again/Next(A/N)?\n"); 
chox: x=getchar(); 
	  if(x=='\n') goto chox; 
	  getchar(); 
	  if((x=='a')||(x=='A')) goto again; 
} 
 
void reading(){int k; 
printf("Please Enter Filename:\n"); 
scanf("%s",filerw); 
for(k=0;k<3;k++){ 
if(strcmp(file[k].filename,filerw)==0){ 
printf("The Content Of File %s Is:\n%s\n",filerw,file[k].content);break;} 
else if(k==3) printf("This File Didn't Exist!\n");} 
} 
 
void writing(){int k; 
printf("Please Enter Filename:\n"); 
scanf("%s",filerw); 
for(k=0;k<3;k++){ 
if(strcmp(file[k].filename,filerw)==0){ 
printf("Please Input The Content To File %s:\n",filerw); 
scanf("%s",file[k].content); 
printf("The Content You Have Writen To File %s Is:\n%s\n",filerw,file[k].content);break;} 
else if(k==3) printf("This File Did Not Exist!\n"); 
} 
} 
 
main(){ 
loop: printf("**************************************\n"); 
      printf("*Thank You For Using This FileSystem!*\n"); 
      printf("*          FilesysPT  V1.0           *\n"); 
      printf("*           CopyRight2003            *\n"); 
      printf("*        PS&TY AllRights Reserved    *\n"); 
      printf("**************************************\n\n\n"); 
loop1:printf("Please Enter Your Choice:\n"); 
      printf("(N)New User\n"); 
      printf("(O)Open User\n"); 
      printf("(D)Delete User\n"); 
      printf("(Q)Query User\n"); 
      printf("(E)Exit\n"); 
      if((con3=='y')||(con3=='Y')){ 
	  printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); 
      printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");} 
cho1: choice=getchar(); 
      if(choice=='\n') goto cho1; 
      if((choice=='n')||(choice=='N')) newu(); 
      else if((choice=='o')||(choice=='O')) {openu();goto loop2;} 
      else if((choice=='d')||(choice=='D')) deleteu(); 
      else if((choice=='q')||(choice=='Q')) {queryu();goto loop1;} 
	  else if((choice=='e')||(choice=='E')) goto end; 
      else{printf("Error!Enter Choice Again:\n");goto loop1;} 
      printf("Prior Menu?Y/N\n"); 
lcon: con=getchar(); 
	  if(con=='\n') goto lcon; 
	  getchar(); 
      if((con=='y')||(con=='Y')) goto loop1; 
loop2:printf("Please Enter Your Choice:\n"); 
      printf("(N)New File\n"); 
      printf("(O)Open File\n"); 
      printf("(C)Copy File\n"); 
      printf("(Q)Query\n"); 
      printf("(E)Exit\n"); 
cho2: choice1=getchar(); 
	  if(choice1=='\n') goto cho2; 
	  getchar(); 
      if((choice1=='n')||(choice1=='N')) newf(); 
      else if((choice1=='o')||(choice1=='O')) {openf();goto loop3;} 
      else if((choice1=='c')||(choice1=='C')) ; 
      else if((choice1=='q')||(choice1=='Q')) {query();goto loop2;} 
      else if((choice1=='e')||(choice1=='E')) goto end; 
      else{printf("Error!Enter Choice Again:\n");goto loop2;} 
	  printf("Go To Prior Menu?Y/N\n"); 
lcon1:con1=getchar(); 
	  if(con1=='\n') goto lcon1; 
	  getchar(); 
      if((con1=='y')||(con1=='Y')) goto loop2; 
loop3:printf("Please Enter Your Choice:\n"); 
      printf("(R)Read\n"); 
      printf("(W)Write\n"); 
      printf("(D)Delete\n"); 
      printf("(C)Close\n"); 
	  choice2=getchar(); 
	  getchar(); 
      if((choice2=='r')||(choice2=='R')) reading(); 
      else if((choice2=='w')||(choice2=='W')) writing(); 
      else if((choice2=='d')||(choice2=='D')) deletef(); 
      else if((choice2=='c')||(choice2=='C')) ; 
      else{printf("Error!Enter Choice Again:\n");goto loop3;} 
	  printf("Go To Prior Menu?Y/N\n"); 
lcon2:con2=getchar(); 
	  if(con2=='\n') goto lcon2; 
	  getchar(); 
      if((con2=='y')||(con2=='Y')) goto loop3; 
printf("Go TO Main Menu?Y/N\n"); 
lcon3:con3=getchar(); 
	  if(con3=='\n') goto lcon3; 
	  getchar(); 
	  if((con3=='y')||(con3=='Y')) 
{printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); 
 printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); 
goto loop;} 
end:; 
}