반응형

 

소스코드

test.c

#include<stdio.h>

int main(void)
{
        FILE *fp;

        fp = fopen("test.txt", "w");
        if (fp == NULL) {
                printf("Failed to open the file \n");
        }
        else {
                printf("Success to open the file \n");
        }
        for (int i = 0; i <= 5; i++) {
                char* str = "hello world\n";
                fputs(str, fp);
        }
        fclose(fp);
        return 0;
}

실행방법

gcc test.c

./a.out

 

출력

vi test.txt

hello world
hello world
hello world
hello world
hello world
hello world

 

반응형

'C > C' 카테고리의 다른 글

[C/C++] __attribute__((packed))에 대한 이해  (1) 2024.03.28
[C/C++] 실행시간 측정하기 time(), clock()  (0) 2023.03.30
[C] C언어 알아두기 (Main)  (0) 2022.11.16
아스키코드표 (ASCII Code table)  (0) 2022.07.18
[C] typedef 사용 예  (0) 2022.05.30