OAIP/23-24/23.c
2024-11-22 21:00:20 +04:00

116 lines
2.1 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "stdio.h"
#include "Windows.h"
#define MAX_LEN 80
char s[MAX_LEN];
void Z1(), Z2(), Z4();
int main1() {
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
Z1();
Z2();
Z4();
return 0;
}
void Z1() {
FILE* fin;
fopen_s(&fin, "D:\\university\\ÎÀÈÏ\\lab\\Temp\\23-24\\in1.txt", "rt");
if (fin == NULL) {
printf("Âõîäíîé ôàéë íå íàéäåí");
return;
}
FILE* fout;
fopen_s(&fout, "D:\\university\\ÎÀÈÏ\\lab\\Temp\\23-24\\out1.txt", "wt");
if (fout == NULL) {
printf("Âûõîäíîé ôàéë íå ñîçäàëñÿ");
return;
}
while (!feof(fin)) {
if (fgets(s, MAX_LEN, fin) != NULL) {
for (int i = 0; s[i] != '\0'; i++) {
if (s[i] == '\t') {
s[i] = '%';
}
}
fprintf(fout, "%s", s);
printf(">>%s<<\n", s);
}
}
fclose(fin);
fclose(fout);
}
char toUpperCase(char c) {
if (c >= 'a' && c <= 'z') return 'A' + (c - 'a');
//printf(" %d = %c ", c, c);
if (c >= 'à' && c <= 'ÿ') return 'À' + (c - 'à');
if (c == '¸') return '¨';
return c;
}
void Z2() {
FILE* fin;
fopen_s(&fin, "D:\\university\\ÎÀÈÏ\\lab\\Temp\\23-24\\in2.txt", "rt");
if (fin == NULL) {
printf("Âõîäíîé ôàéë íå íàéäåí");
return;
}
FILE* fout;
fopen_s(&fout, "D:\\university\\ÎÀÈÏ\\lab\\Temp\\23-24\\out2.txt", "wt");
if (fout == NULL) {
printf("Âûõîäíîé ôàéë íå ñîçäàëñÿ");
return;
}
while (!feof(fin)) {
if (fgets(s, MAX_LEN, fin) != NULL) {
for (int i = 0; s[i] != '\0'; i++) {
s[i] = toUpperCase(s[i]);
}
fprintf(fout, "%s", s);
printf(">>%s<<\n", s);
}
}
fclose(fin);
fclose(fout);
}
void Z4() {
FILE* fin;
fopen_s(&fin, "D:\\university\\ÎÀÈÏ\\lab\\Temp\\23-24\\in4.txt", "rt");
if (fin == NULL) {
printf("Âõîäíîé ôàéë íå íàéäåí");
return;
}
FILE* fout;
fopen_s(&fout, "D:\\university\\ÎÀÈÏ\\lab\\Temp\\23-24\\out4.txt", "wt");
if (fout == NULL) {
printf("Âûõîäíîé ôàéë íå ñîçäàëñÿ");
return;
}
while (!feof(fin)) {
if (fgets(s, MAX_LEN, fin) != NULL) {
for (int i = 0; s[i] != '\0'; i++) {
if (!((s[i] >= 'a' && s[i] <= 'z') || (s[i] >= 'A' && s[i] <= 'Z')))
s[i] = '_';
}
fprintf(fout, "%s", s);
printf(">>%s<<\n", s);
}
}
fclose(fin);
fclose(fout);
}