OAIP_Mirror/lab23/files/out5.txt
2024-11-22 20:10:38 +04:00

42 lines
812 B
Plaintext

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