-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path소스.cpp
More file actions
137 lines (114 loc) · 2.4 KB
/
소스.cpp
File metadata and controls
137 lines (114 loc) · 2.4 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<sys/stat.h>
#include<time.h>
#include<errno.h>
#include<ctype.h>
#include<io.h>
#include<iostream>
struct file
{
int save;
char title[150];
};
char* timeToString(struct tm *t);
void file(char voca[150]);
void main()
{
char search[150];
printf("찾고 싶은 단어는? : ");
scanf("%s", search);
file(search);
system("pause");
}
void file(char voca[150])
{
struct _finddata_t fd;
struct file *title, temp;
struct _stat buf;
long handle;
int i = 0, k, num = 0;
int result = 1;
char *st;
char str[150] = { 0 };
char str1[150] = { 0 };
handle = _findfirst("C:\*.txt", &fd);
if (handle == -1)
return;
while (result != -1)
{
result = _findnext(handle, &fd);
num++;
}
title = (struct file *)calloc(num, sizeof(struct file));
result = 1;
handle = _findfirst("C:\*.txt", &fd);
while (result != -1)
{
strcpy(title[i].title, fd.name);
result = _findnext(handle, &fd);
i++;
}
_findclose(handle);
strcpy(str1, voca);
for (i = 0; i < num; i++)
{
FILE * fp = fopen(title[i].title, "rt");
while (!feof(fp))
{
fscanf(fp, "%s", str);
st = &str[0];
if (isalpha(str[0]) == 0)
{
st++;
}
if (_strnicmp(st, str1, strlen(str1)) == 0)
{
title[i].save++;
}
}
fclose(fp);
}
for (i = 0; i < num; i++)
{
for (k = 0; k < num - 1; k++)
{
if (title[k].save < title[k + 1].save)
{
temp = title[k];
title[k] = title[k + 1];
title[k + 1] = temp;
}
}
}
for(i = 0; i < num; i++)
{
if (_stat(title[i].title, &buf) != 0)
{
switch (errno)
{
case ENOENT:
fprintf(stderr, "File %s not found.\n", title[i].title); break;
case EINVAL:
fprintf(stderr, "Invalid parameter to _stat.\n"); break;
default:
fprintf(stderr, "Unexpected error in _stat.\n");
}
}
else
{
printf("파일 이름 : %s, 단어 개수 : %d, 수정된 날짜 : %s 누적 개수 : %d\n", title[i].title, title[i].save, timeToString(localtime(&buf.st_mtime)), i + 1);
}
}
free(title);
}
char* timeToString(struct tm *t)
{
static char s[20];
sprintf(s, "%04d-%02d-%02d %02d:%02d:%02d",
t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
t->tm_hour, t->tm_min, t->tm_sec
);
return s;
}