PDA

View Full Version : how to get specific parts of a string to be bold in sprintf(), any help appreciated



01-24-2002, 05:55 AM
i want just the words "allowable stress" to be bold, anyone know how to do this? thanks

sprintf(fbstring, "Allowable Stress: %f_psi", fb);

Thug
01-24-2002, 10:17 AM
I am assumming that you have a routine that bolds text.

sprintf will not bold your string. All sprintf will do is combine all you variables into a formated string (without being bold, italized ...). If you want to bold "allowable stress" create two image files one with bold letters and one being normal. print "allowable stress" using the bold letters and your psi noramlly.

Nathan
01-24-2002, 11:47 AM
Originally posted by paranoid_android:
i want just the words "allowable stress" to be bold, anyone know how to do this? thanks

sprintf(fbstring, "Allowable Stress: %f_psi", fb);

If you are writing this program for Unix, you need to use escape characters. The escape codes are built out of the following:

Attribute codes:
00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed

Text color codes:
30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white

Background color codes:
40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white

The codes are combined in the following manner:


#include <stdio.h>

#define BOLD "\x1B[1;37m"
#define RESET "\x1B[0;0m"

void main() {
printf("%sAllowable Stress:%s %f_psi\n", BOLD, RESET, 100.2);
}


You can combine many of the codes together by chaining them:

Ex. green underlined with a purple background:

#define UGLY "\x1B[4;32;45m"

Not all terminals support these color codes, though. Some will just print them to the screen as ugly characters. Others will change the colors around on you (my terminal displays bold white as yellow). Good luck with it.

01-24-2002, 06:34 PM
thanks for the help http://www.opengl.org/discussion_boards/ubb/smile.gif