Thread: A small problem with TextOut()

  1. #1
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768

    A small problem with TextOut()

    Hi, I have this string "line1\nline2\nline3\n", that I would like to print out with TextOut(), but since TextOut() doesn't support '\n', I had to make it myself.
    And It does print "line1" and under it "line2", but that's it, why?
    Where is "line3"?

    "line1\nline2\nline3\n" is been passed inside msg

    Code:
    void preview_text(HDC hDC, int x, int y, char *msg)
     {
       int i, j=0;
       char line[100]={0}; 
    
       for (i=0; i<strlen(msg); ++i)
        {
          if (msg[i]=='\n')
           {
             TextOut(hDC, x, y, line, strlen(line));
             memset(line, '\0', 100);
             y += 13;
             j = 0;
           }
          else
            line[j++] = msg[i];
        }
     }

    Thanks.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    81
    if you don't want to go threw all that you could try using DrawText i think that allows the \n's

  3. #3
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    Thanks, I will check that out... But still what's wrong with this code? It suppost to work right.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  4. #4
    Registered User
    Join Date
    Jun 2003
    Posts
    70
    code:-----------------------------------------------------------------------------

    void preview_text(HDC hDC, int x, int y, char *msg)
    {
    int i, j=0;
    char line[100]={0};

    for (i=0; i<strlen(msg); ++i)
    {
    if (msg[i]=='\n')
    {
    TextOut(hDC, x, y, line, strlen(line));
    memset(line, '\0', 100);
    y += 13;
    j = 0;
    }
    else
    line[j++] = msg[i];
    }
    }
    --------------------------------------------------------------------------------

    Your code is looking perfect. Pls check the strings's entirety at the place from where you are calling this function.

    I mean whether this function get "line1\nline2\nline3\n" or "line1\nline2\nline3" ?
    Chintan R Naik

  5. #5
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    the input!!! of course... it only calls for TextOut() when it sees '\n'...

    Thanks.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Small Problem with double and integer adding?
    By Nathan the noob in forum C++ Programming
    Replies: 5
    Last Post: 03-28-2009, 04:16 PM
  2. Visual C++ small problem
    By gadu in forum C++ Programming
    Replies: 0
    Last Post: 03-10-2009, 10:45 PM
  3. Small problem with this array...
    By Merholtz in forum C Programming
    Replies: 7
    Last Post: 11-03-2008, 04:16 PM
  4. Help with a small problem (beginner)
    By piffo in forum C Programming
    Replies: 13
    Last Post: 09-29-2008, 04:37 PM
  5. Need Big Solution For Small Problem
    By GrNxxDaY in forum C++ Programming
    Replies: 8
    Last Post: 08-01-2002, 03:23 AM