Skip to content
Snippets Groups Projects
snprintf.c 509 B
Newer Older
Bruce Cowan's avatar
Bruce Cowan committed
/*
 * SPDX-FileCopyrightText: 2018 Bruce Cowan <bruce@bcowan.me.uk>
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
Bruce Cowan's avatar
Bruce Cowan committed
 */

Bruce Cowan's avatar
Bruce Cowan committed
#include <stdio.h>

#ifdef __GNUC__
    #pragma GCC diagnostic ignored "-Wformat-truncation"
#endif

Bruce Cowan's avatar
Bruce Cowan committed
int
main (void)
{
    char string[8 + 1];

    printf ("The following string should be 10 digits long\n");
    snprintf (string, sizeof(string), "1234567890");
    printf ("%s\n", string);
    printf ("But it's only 8, which is one fewer than the char array length\n");

    return 0;
}