#include<stdio.h> #include<stdlib.h> #include<conio.h>

typedef struct afd { char filename[10]; int pcode; int length; } afd;

typedef struct mfd { char username[10]; afd* next; } mfd;

typedef struct ufd { char filename[10]; int opening; ufd* next; } ufd;

mfd mfd[5], *p1, *q1;

afd *ufd, *p2, *q2; char x[10]; ufd *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", p2->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 && (strcmp(q2->filename, x) != 0)) q2 = q2->next; if (q2->next == NULL) { q2->next = p2; strcpy(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 && (strcmp(p2->filename, x) != 0)) { p2 = p2->next; if (strcmp(p2->filename, x) == 0) if (i) q3 = q3->next; } if (strcmp(q3->filename, x) == 0) printf("the file is on the afd\n"); else { if (i == 0) p3 = afd; else q3->next = p3; i++; strcpy(p3->filename, x); p3->opening = i; p3->next = NULL; printf("file number=%d\n", i); } print(); }

void pdelete() { printf("the filename to delete:"); scanf("%s", x); printf("\n"); p3 = afd; q3 = afd; if (strcmp(p3->filename, x) != 0) { q3 = p3; p3 = p3->next; } else { q3->next = p3->next; free(p3); } p2 = ufd; q2 = ufd; if (strcmp(p2->filename, x) != 0) { 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 (strcmp(q3->filename, x) != 0 && q3->next) { p3 = q3; q3 = q3->next; } if (q3->next || strcmp(q3->filename, x) != 0) { 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); } 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; }

int 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] = (mfd*)malloc(sizeof(mfd)); p1 = mfd[i]; strcpy(p1->username, x); p1->next = NULL; printf("one user file numbers k="); scanf("%d", &k); p2 = (afd*)malloc(sizeof(afd)); for (j = 0; j < k; j++) { printf("input ufd name:"); scanf("%s", x); p2->length = s; p2->next = NULL; ufd = p2; p1->next = p2; } printf("input user name you want to operate:"); scanf("%s", x); while (strcmp(x, mfd[i]->username) != 0) printf("not find ,input again!"); p2 = mfd[i]->next; il = 0; } while (t != '4') { printf("------------------\n"); printf("1:create the file\n"); printf("2:open the file\n"); printf("3:delete the file\n"); printf("4:bye the file\n"); printf("------------------\n"); t = getchar(); switch (t) { case '1': pcreat(); break; case '2': popen(); break; case '3': pdelete(); break; case '4': pbye(); break; default: break; } } return 0; }

C语言文件管理系统代码实现

原文地址: https://www.cveoy.top/t/topic/f1wH 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录