fputs() — 文字列を書き込む
形式
#include <stdio.h>
int fputs(const char *string, FILE *stream);言語レベル
ANSI
スレッド・セーフ
はい
説明
fputs() 関数は、 string を現在位置の出力 stream にコピーします。 ストリングの最後のヌル文字 (¥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" );
}