-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminimize.cpp
More file actions
53 lines (44 loc) · 1.07 KB
/
minimize.cpp
File metadata and controls
53 lines (44 loc) · 1.07 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
#include <stdio.h>
#include <string.h>
void removeNewlinesAndSpaces(FILE* input, FILE* output) {
char str[2048];
while ((fgets(str, 2048, input)) != NULL) {
int i = 0;
int len = strlen(str);
if (len > 0 && str[len-1] == '\n') {
str[len-1] = '\0';
len--;
}
while (str[i] == ' ') {
i++;
}
if (i > 0) {
memmove(str, str+i, len-i+1);
}
fprintf(output, "%s", str);
}
}
int main() {
FILE* inputFile;
FILE* outputFile;
// 打开输入文件
inputFile = fopen("content.html", "r");
if (inputFile == NULL) {
printf("无法打开输入文件。\n");
return 1;
}
// 创建并打开输出文件
outputFile = fopen("content.min.html", "w");
if (outputFile == NULL) {
printf("无法创建输出文件。\n");
return 1;
}
// 删除换行符和四个一组的空格
removeNewlinesAndSpaces(inputFile, outputFile);
// 关闭文件
fclose(inputFile);
fclose(outputFile);
printf("处理完成。\n");
getchar();
return 0;
}