Recommanded Free YOUTUBE Lecture: <% selectedImage[1] %>

<a href="/modules/moniwiki/wiki.php/manSearch?google=none&name=fputs">fputs</a>(3)

1장. fputs(3)

차례
1.1절. 사용법
1.2절. 설명
1.3절. 반환값
1.4절. 예제

열린 파일 스트림으로 문자열을 출력한다.


1.1절. 사용법

#include <stdio.h>

int fputs(const char *s, FILE *stream);
		


1.2절. 설명

fputs는 fopen(3)등으로 열림 파일스트림인 stream 에 문자열 s 를 쓴다. 이때 s 마지막에 '\0' 은 붙지 않는다. 또한 '\n'(개행문자) 가 붙지도 않는다.


1.3절. 반환값

성공할경우 음이 아닌 수를 되돌려주며, 에러가 발생했을경우 -1이나 EOF 에러를 되돌려준다.


1.4절. 예제

#include <string.h>

#include <stdio.h>

int main()
{
    FILE *fp, *fp2; 
    int a;
    fp = fopen("fputs.txt", "w");
    fputs("hello\n", fp);

    fputs("job is success\n", stdout);
    fclose(fp);
}
		
먼저 fopen 을 이용해서 파일 스트림을 연다음에 fputs 를 이용해서 열린 파일 스트림에 "hello\n" 을 입력했다. 그리고 stdout(표준출력) 으로 "job is success\n" 을 입력했다. "job is success\n" 은 화면으로 출력되며 "hello\n" 은 fputs.txt 로 써지게 된다.