Thread: New programmer: how to print a string

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    9

    New programmer: how to print a string

    I used fgets to store strings into the data of my nodes.
    My problem is that fgets also stores the new line character into my node's data.
    I want to print the string to get this:

    The line: "My first node's line" has been deleted.

    I tried:
    Code:
    printf("\nThe line: "%s" has been deleted.", nodeToDelete->data);
    The compiler cant work with the doubling up of ""
    Even though I need to print the "", I tried:

    Code:
    printf("\nThe line: %s has been deleted.", nodeToDelete->data);
    And it prints:

    Code:
    The line: My first node's line
    has been deleted
    Which is not what I want at all!
    Last edited by 9988776655; 12-27-2007 at 07:41 PM.

  2. #2
    Registered User OnionKnight's Avatar
    Join Date
    Jan 2005
    Posts
    555
    You can "remove" the newline by replacing the last '\n' with a '\0'. You can use strrchr() for this.
    Also if you want to print a " you need to escape it with a backslash, \"
    Otherwise the compiler will think that you want to terminate the string.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. String Class
    By BKurosawa in forum C++ Programming
    Replies: 117
    Last Post: 08-09-2007, 01:02 AM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  3. Replies: 4
    Last Post: 03-03-2006, 02:11 AM
  4. What kind of programs should I start writing?
    By Macabre in forum C++ Programming
    Replies: 23
    Last Post: 04-12-2003, 08:13 PM
  5. Again Character Count, Word Count and String Search
    By client in forum C Programming
    Replies: 2
    Last Post: 05-09-2002, 11:40 AM