OAIP_Mirror/lab23/files/text1.txt

42 lines
728 B
Plaintext
Raw Normal View History

2024-11-22 15:59:17 +04:00
#include <stdio.h>
#define BUF_LEN 128
2024-11-22 14:42:10 +04:00
2024-11-22 15:59:17 +04:00
void task1() {
puts("===== task1 =====");
2024-11-22 14:42:10 +04:00
2024-11-22 15:59:17 +04:00
char infilepath[] = "files/text1.txt";
FILE* fin = fopen(infilepath, "r");
if (fin == NULL) {
printf("Cannot open file %s\n", infilepath);
return;
}
2024-11-22 14:42:10 +04:00
2024-11-22 15:59:17 +04:00
char outfilepath[] = "files/out1.txt";
FILE* fout = fopen(outfilepath, "w");
if (fin == NULL) {
printf("Cannot open file %s\n", outfilepath);
return;
}
2024-11-22 14:42:10 +04:00
2024-11-22 15:59:17 +04:00
char buf[BUF_LEN];
while (fgets(buf, BUF_LEN, fin) != NULL) {
for (int i = 0; buf[i] != '\0'; i++) {
if (buf[i] == '\t') {
buf[i] = '%';
}
}
fprintf(fout, "%s", buf);
printf(">>%s<<", buf);
}
fclose(fin);
fclose(fout);
}
int main() {
task1();
return 0;
}