C语言文件管理系统代码示例
#include <stdio.h>
typedef struct afd { char filename[10]; int pcode; int length; }*linkt;
typedef struct mfd { char username[10]; linkt next; }*linkf;
typedef struct ufd { char filename[10]; int opening; struct ufd *next; }*link;
linkf mfd[5], p1, q1; linkt ufd, p2, q2; char x[10]; link afd, p3, q3; int t, r, l, i, k, n, s, m, j, il;
void print( ) { for(i=0;i<n;i++) { printf("%s", mfd[i]->username); p2=mfd[i]->next; while(p2) { printf("%s", ufd->filename); printf("%s%d%d", p2->filename, p2->pcode, p2->length); p2=p2->next; } } if(i>0) { p3=afd; while(p3) { printf("%s%d", afd->filename, afd->opening); printf("%s%d", p3->filename, p3->opening); p3=p3->next; } } }
void pcreat() { printf("create name:\n"); scanf("%s", x); q2=ufd; while(q2->next && (q2->filename != x)) q2=q2->next; if(q2->next == NULL) { q2->next=p2; p2->filename=x; printf("create code=\n"); scanf("%d", &m); p2->pcode=m; printf("create length=\n"); scanf("%d", &s); p2->length=s; p2->next=NULL; } else printf("the file is exist\n"); }
void popen( ) { p2=ufd; printf("input filename=\n"); scanf("%s", x); while(p2->next && (p2->filename != x)) { p2=p2->next; if(p2->filename == x) if(i) q3=q3->next; } if(q3->filename == x) printf("the file is on the afd\n"); else { if(i==0) p3=afd; else q3->next=p3; i++; p3->filename=x; p3->opening=i; p3->next=NULL; printf("file number=%d\n", i); } else printf("error"); print(); }
void pdelete() { printf("the filename to delete:"); scanf("%s", x); printf("\n"); p3=afd; q3=afd; if(p3->filename != x) { q3=p3; p3=p3->next; } else { q3->next=p3->next; free(p3); } p2=ufd; q2=ufd; if(p2->filename != x) { while(p2->next) { q2=p2; p2=p2->next; } } else { q2->next=p2->next; free(p2); printf("the file is deleted\n"); }
}
print(); }
void pclose() { int j; printf("input close filename:"); scanf("%s", x); q3=afd; p3=q3; j=0; while(q3->filename != x && (q3->next)) { p3=q3; q3=q3->next; } if(q3->next || (q3->filename != x)) { p3->next=q3->next; free(q3); printf("end of close\n"); p3=afd; while(p3->next) { j++; p3=p3->next; } if(j==0) il=0; printf("afd file number=%d", il); else printf("error"); } print(); }
void pbye() { p2=ufd; while(p2) { printf("%s%d%d\n", p2->filename, p2->pcode, p2->length); p2=p2->next; } printf("2008-11-20"); t=1; }
main() { char t; printf("user number n="); scanf("%d", &n); for(i=0;i<n;i++) { printf("user mfd and the filename:\n"); scanf("%s", x); mfd[i]=(linkf)malloc(sizeof(struct mfd)); p1=mfd[i]; p1->username=x; p1->next=NULL; printf("one user file numbers k="); scanf("%d", &k); p2=(linkt)malloc(sizeof(struct afd)); for(j=0;j<k;j++) { printf("input ufd name:"); scanf("%s", x); p2->length=s; p2->next=NULL; ufd=p2; ufd->next=p2; } printf("input user name you want to operate:"); scanf("%s", x); while(x != mfd[i]->username) printf("not find ,input again!"); ufd=mfd[i]->next; il=0; } while(t) { printf("------------------\n"); printf("1:create the file"); printf("2:open the file"); printf("1:delete the file"); printf("1:bye the file"); printf("------------------\n"); t=getche(); switch(t) { case '1': pcreat(); break; case '2': popen( ); break; case '3': pdelete(); break; case '4': pbye(); break; default: break; } } }
原文地址: https://www.cveoy.top/t/topic/f1wG 著作权归作者所有。请勿转载和采集!