C Tutorial/stdio.h/sprintf

Материал из C\C++ эксперт
Перейти к: навигация, поиск

sprintf

Item Value Header file stdio.h Declaration int sprintf(char *buf, const char *format, ...); Function It is identical to printf() except that the output is a char array. Return returns the number of characters actually placed into the array.

sprintf() provides no bounds checking. See snprintf for an alternative.


#include <stdio.h>
int main(void){
  char str[80];
  sprintf(str,"%s %d %c", "one", 2, "3");
  printf("%s", str);
}