아래의 순서로 프로그램을 작성하라.
1. 입력파일로 input.txt를 작성한다. 영어 문장 아무거나…
2. 위의 input.txt를 읽어서 아래와 같이 모두 대문자로, 그다음은 모두 소문자로 위 영어문장을 output.txt파일에 출력하는 프로그램을 작성하라.
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
|
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE* fp, * fp2;
int num, sum = 0;
char line[100];
char line2[100];
int i;
fp = fopen("input.txt", "rt");
fp2 = fopen("output.txt", "wt");
if (fp == NULL)
{
printf("file open error!\n");
return 1;
}
if (fp2 == NULL)
{
printf("파일 오픈 에러!\n");
return 1;
}
while (fgets(line, sizeof(line), fp)!=NULL) {
for (i=0; line[i] != '\0'; i++) {
line[i] = toupper(line[i]);
}
fprintf(fp2, "%s", line);
}
fclose(fp);
fprintf(fp2, "\n");
fp = fopen("input.txt", "rt");
if (fp == NULL)
{
printf("file open error!\n");
return 1;
}
while (fgets(line, sizeof(line), fp)!=NULL) {
for (i = 0; line[i] != '\0'; i++) {
line2[i] = tolower(line[i]);
}
line2[i] = '\0';
fprintf(fp2, "%s", line2);
}
fclose(fp);
fclose(fp2);
}
|
cs |
'대학교 1-2 > 컴프' 카테고리의 다른 글
HW12_1 (0) | 2023.12.08 |
---|---|
LAB12_2_2_수정 (0) | 2023.12.08 |
2020 중간_1 (0) | 2023.10.25 |
challenge6d (0) | 2023.10.12 |
challenge6b (1) | 2023.10.12 |