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

i want just the words “allowable stress” to be bold, anyone know how to do this? thanks

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

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.

Originally posted by paranoid_android:
[b]i want just the words “allowable stress” to be bold, anyone know how to do this? thanks

sprintf(fbstring, “Allowable Stress: %f_psi”, fb);[/b]

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
", 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.

thanks for the help