SNPRINTF()

snprintf(str, size, format, ...);
#include <stdio.h>

#define BUFFER_SIZE 50  // Changed name to avoid confusion

int main()
{
    char buffer[BUFFER_SIZE]; // Declare a character array named 'buffer'

    printf("This is using printf\n");
    snprintf(buffer, sizeof(buffer), "The side of BUFFER is %d", BUFFER_SIZE);

    printf("%s\n", buffer); // Print the contents of the buffer

    return 0;
}

 * use snprintf in conjunction w/ fgets IOT better control user input
    - limit use of printf to displaying data that doesn't involve user input

Last updated