셀맨1 2017. 1. 31. 13:24
반응형

텍스트 파일을 열어서 파일 안에 들어 있는 문자들을 모두 대문자로 변경하는 프로그램을 작성한다.


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
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#define SIZE 100
 
int main(void)
{
    FILE *fp=NULL;
    char a[SIZE];
    int i;
    if((fp=fopen("1.txt","r+"))==NULL)
    {
        printf("잘못된 파일 열기\n");
        exit(1);
    }
    fgets(a,SIZE,fp);
    printf("입력 파일 : ");
    for(i=0;a[i]!=NULL;i++)
    {
        printf("%c ", a[i]);
    }
    printf("\n");
    fseek(fp,0,SEEK_SET);
    for(i=0;a[i]!=NULL;i++)
    {
        a[i]=toupper(a[i]);
    }
    fputs(a,fp);
    fseek(fp,0,SEEK_SET);
    fgets(a,SIZE,fp);
    printf("출력 파일 : ");
    for(i=0;a[i]!=NULL;i++)
    {
        printf("%c ", a[i]);
    }
    printf("\n");
    return 0;
}
cs




반응형