Results 1 to 4 of 4

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

  1. #1
    Guest

    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);

  2. #2
    Member Newbie
    Join Date
    Mar 2001
    Posts
    48

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

    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.

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2002
    Location
    Ghlin (Belgium)
    Posts
    2

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

    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.

  4. #4
    Guest

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

    thanks for the help

Similar Threads

  1. Replies: 2
    Last Post: 06-15-2015, 03:26 AM
  2. sprintf and new line
    By Zath in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 06-30-2006, 11:06 AM
  3. Maya Exporter sprintf buffer overrun
    By stuartbryson in forum COLLADA
    Replies: 1
    Last Post: 03-25-2005, 10:22 AM
  4. Bold lines
    By MACnus in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 05-20-2004, 06:52 AM
  5. GLUT Tutorial available, comments appreciated
    By Antonio in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 09-26-2000, 04:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean