Created
November 10, 2015 09:34
-
-
Save bzdgn/0a19bf0865815d331702 to your computer and use it in GitHub Desktop.
Sprintf and Buffer Sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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