sprintf(3) — Linux manual page

NAME | LIBRARY | SYNOPSIS | DESCRIPTION | ATTRIBUTES | STANDARDS | HISTORY | BUGS | SEE ALSO | COLOPHON

sprintf(3)               Library Functions Manual              sprintf(3)

NAME         top

       sprintf, vsprintf - string print formatted

LIBRARY         top

       Standard C library (libc, -lc)

SYNOPSIS         top

       #include <stdio.h>

       int sprintf(char *restrict str,
                   const char *restrict format, ...);
       int vsprintf(char *restrict str,
                   const char *restrict format, va_list ap);

   Feature Test Macro Requirements for glibc (see
   feature_test_macros(7)):

       snprintf(), vsnprintf():
           _XOPEN_SOURCE >= 500 || _ISOC99_SOURCE
               || /* glibc <= 2.19: */ _BSD_SOURCE

DESCRIPTION         top

       These functions are equivalent to snprintf(3) and vsnprintf(3),
       except that no check for buffer overrun is performed (see BUGS
       below).

ATTRIBUTES         top

       For an explanation of the terms used in this section, see
       attributes(7).
       ┌───────────────────────────────┬───────────────┬────────────────┐
       │ Interface                     Attribute     Value          │
       ├───────────────────────────────┼───────────────┼────────────────┤
       │ sprintf(), vsprintf()         │ Thread safety │ MT-Safe locale │
       └───────────────────────────────┴───────────────┴────────────────┘

STANDARDS         top

       C11, POSIX.1-2008.

HISTORY         top

       C89, POSIX.1-2001.

BUGS         top

       See printf(3).

   sprintf(), vsprintf()
       Because sprintf() and vsprintf() assume an arbitrarily long
       string, callers must be careful not to overflow the actual space;
       this is often impossible to assure.  Note that the length of the
       strings produced is locale-dependent and difficult to predict.
       Use snprintf() and vsnprintf() instead (or asprintf(3) and
       vasprintf(3)).

SEE ALSO         top

       asprintf(3), snprintf(3)

COLOPHON         top

       This page is part of the man-pages (Linux kernel and C library
       user-space interface documentation) project.  Information about
       the project can be found at 
       ⟨https://www.kernel.org/doc/man-pages/⟩.  If you have a bug report
       for this manual page, see
       ⟨https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/tree/CONTRIBUTING⟩.
       This page was obtained from the tarball man-pages-6.18.tar.gz
       fetched from
       ⟨https://mirrors.edge.kernel.org/pub/linux/docs/man-pages/⟩ on
       2026-05-24.  If you discover any rendering problems in this HTML
       version of the page, or you believe there is a better or more up-
       to-date source for the page, or you have corrections or
       improvements to the information in this COLOPHON (which is not
       part of the original manual page), send a mail to
       man-pages@man7.org

Linux man-pages 6.18            2025-12-07                     sprintf(3)

Pages that refer to this page: gawk(1)aprintf(3)asprintf(3)ecvt(3)ecvt_r(3)gcvt(3)lber-encode(3)qecvt(3)sscanf(3)stdio(3)strfmon(3)strftime(3)wprintf(3)slapd.conf(5)slapd-config(5)feature_test_macros(7)slappasswd(8)