Output text containing '\r' as new line character.

This is a discussion on Output text containing '\r' as new line character. within the C Programming forums, part of the General Programming Boards category; I'm trying to print out some text returned from ms word. The trouble is that word apparently uses '\r' as ...

  1. #1
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544

    Output text containing '\r' as new line character.

    I'm trying to print out some text returned from ms word. The trouble is that word apparently uses '\r' as its solitary new line character.

    When passed to printf or puts this will reset the cursor to the start of the line instead of moving to the next line.

    Does anybody know a simple way to output this text to the console without looping through it?

    Thanks.

  2. #2
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Posts
    463
    you could save the text from MSWord into an array and then putc() it, instead of puts or printf. If you had to you could look for \r and then do \n instead.

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    How does your program get this data "returned from MS Word"?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    >>you could save the text from MSWord into an array and then putc() it, instead of puts or printf. If you had to you could look for \r and then do \n instead<<

    Thanks. It is only some sample code for a library I'm writing so I might just output it in a MessageBox instead to save some hassle. I thought there might be a simple way to set the console mode to treat '\r' as a new line (what happens if you have macintosh text?).

    >>How does your program get this data "returned from MS Word"?<<

    It's retrieved via COM. The code is somewhat similar(only in C) to the following vbscript which demonstrates that word uses '\r' as its new line character:
    Code:
    Set wdDoc = GetObject("test.doc")
    
    str = wdDoc.Range.Text
    
    For x = 1 to len(str)
    	chCurrent = mid(str, x, 1)
    	If (asc(chCurrent) = 13) Then
    		newstr = newstr & "(13)"
    	Else
    		newstr = newstr & chCurrent
    	End If
    Next
    
    Msgbox newstr

  5. #5
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Posts
    463
    /r is always going to follow C's default behavior for it. Unfortunately, finding and replacing it yourself is the easy way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  2. How to use FTP?
    By maxorator in forum C++ Programming
    Replies: 8
    Last Post: 11-04-2005, 03:17 PM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 11:03 AM
  4. SSCANF help
    By mattz in forum C Programming
    Replies: 7
    Last Post: 12-10-2001, 04:53 PM
  5. text line termination
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 09-09-2001, 05:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21