반응형

 

소스코드

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

 

반응형