C Tutorial/stdio.h/snprintf — различия между версиями

Материал из C\C++ эксперт
Перейти к: навигация, поиск
м (1 версия: Импорт контента...)
 
(нет различий)

Версия 17:21, 25 мая 2010

snprintf

Item Value Header file stdio.h Declaration int snprintf(char * restrict buf, size_t num, const char * restrict format, ...) Function It is identical to sprintf() except that a maximum of num-1 characters will be stored.


<source lang="cpp">#include <stdio.h> int main () {

 char buffer [50];
 int n, a=5, b=3;
 n=snprintf (buffer, 5,"%d plus %d is %d", a, b, a+b);
 printf ("[%s] is a %d char long string\n",buffer,n);
 return 0;

}</source>