fputs() — 스트링 쓰기
형식
#include <stdio.h>
int fputs(const char *string, FILE *stream);
언어 레벨
ANSI
스레드세이프
예
설명
fputs() 함수는 string을 현재 위치의 출력 stream으로 복사합니다. 스트링 끝의 null 문자 (\0)를 복사하지 않습니다.
리턴값
오류가 발생하면 fputs() 함수는 EOF을 리턴합니다. 그렇지 않으면, 음수가 아닌 값을 리턴합니다.
fputs() 함수는 type=record로 열린 파일에 대해 지원되지 않습니다.
fputs()의 errno 값에 대한 정보는 fputc() — 문자 쓰기의 내용을 참조하십시오.
예
이 예는 스트링을 스트림에 씁니다.
#include <stdio.h>
#define NUM_ALPHA 26
int main(void)
{
FILE * stream;
int num;
/* Do not forget that the '\0' char occupies one character */
static char buffer[NUM_ALPHA + 1] = "abcdefghijklmnopqrstuvwxyz";
if ((stream = fopen("mylib/myfile", "w")) != NULL )
{
/* Put buffer into file */
if ( (num = fputs( buffer, stream )) != EOF )
{
/* Note that fputs() does not copy the \0 character */
printf( "Total number of characters written to file = %i\n", num );
fclose( stream );
}
else /* fputs failed */
perror( "fputs failed" );
}
else
perror( "Error opening myfile" );
}