Skip to content

Instantly share code, notes, and snippets.

@bzdgn
Created November 10, 2015 09:34
Show Gist options
  • Save bzdgn/0a19bf0865815d331702 to your computer and use it in GitHub Desktop.
Save bzdgn/0a19bf0865815d331702 to your computer and use it in GitHub Desktop.
Sprintf and Buffer Sample
#include <stdio.h>
#define BUFFER_SIZE 100
int main()
{
char * font = "Myriad Pro";
int size = 32;
char * message = "Hello world";
char buffer[BUFFER_SIZE];
printf("Buffer Size: %d\n", BUFFER_SIZE);
printf("Message Size: %d\n", strlen(message));
if( strlen(message) > BUFFER_SIZE )
{
printf("Not enough buffer, program halted!\n");
return 1;
}
sprintf(buffer,
"<html><body><p style='font-family:%s;font-size:%dpx'>%s</p></body></html>",
font,
size,
message);
printf("%s\n", buffer);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment