1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <stdio.h>
#include <string.h>
 
typedef struct {
    char name[20];
    int size;
}file;
 
int cnt = 0;
 
int main(void) {
    char comm[10];
    file folder[20= { "picnic.txt"82"comic.txt"318"house.txt"287 };
    int i;
 
    printf("**하나의 폴더 내의 파일의 생성, 삭제, 변경, 조회 프로그램**\n");
    printf("+---------명령어  설명---------+\n");
    printf("l new    - 생성     dir - 조회 l\n");
    printf("l rename - 변경     del - 삭제 l\n");
    printf("l exit   - 종료                l\n");
    printf("+------------------------------+\n");
 
    while (1) {
        printf("command>> "); scanf("%s", comm);
        if (!strcmp(comm, "exit")) {
            printf("Good bye!\n");
            break;
        }
        else if (!strcmp(comm, "new")) {
            printf("filename : %s\n", folder[cnt].name);
            printf("filesze : %d\n", folder[cnt].size);
            printf("A new file is created!\n\n");
            cnt++;
        }
        else if (!strcmp(comm, "dir")) {
            for (i = 0; i < cnt; i++) {
                printf("%d) %s [%d bytes]\n", i + 1, folder[i].name, folder[i].size);
            }
            printf("\n");
        }
        else if (!strcmp(comm, "rename")) {
            char seek[20];
            printf("original filename : "); scanf("%s", seek); fflush(stdin);
            for (i = 0; i < cnt; i++) {
                if (!strcmp(seek, folder[i].name)) { // 이부분이 궁금한데 이렇게 하면 folder[0].name 만 되고 뒤에꺼는 안됨 어떻게써야 깔쌈한코딩?
                    printf("new filename : "); scanf("%s", folder[i].name); fflush(stdin);
                    printf("The filename is changed!\n");
                    break;
                }
                else {
                    printf("입력한 파일명이 존재하지 않습니다!\n");
                    break;
                }
            }
            printf("\n");
        }
        else if (!strcmp(comm, "del")) {
        }
        else printf("Invalid command!\n");
    }
 
    return 0;
}
cs