トップページ > キーワード検索 > sprintf()
C言語規格
C言語(その他)
プログラム
その他
sprintf()
機能 指定の書式に従って引数の配列へデータを出力することを表す。
定義 #include <stdio.h>

int sprintf ( char * s, const char * format, ... );

※C99規格では以下の定義となる
int sprintf ( char * restrict s, const char * restrict format, ... );
引数
s出力する配列(char型配列)へのポインタ
format変換書式文字列。詳細はprintf関数を参照
...出力する変数群(可変引数)
戻り値 書き出された文字数を返す。
エラーが発生した場合は負の値を返す。
実装例
#include <stdio.h>

int main(void)
{
    char s[10];
    int a = 123;
    
    sprintf(s, "a=%d", a);
    
    printf("s=%s\n", s);
    
    return 0;
}
実行結果
s=a=123





inserted by FC2 system