Thread: String Manipulation Problem

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    18

    String Manipulation Problem

    I have a string right, which has data put into it from a file I am reading from.

    It reads each line of the file and stores it in this variable. Anyway.
    It appears that when it is storing this string in this variable it is also adding a "\n"

    Meaning when I join the strings together instead of looking like this:

    string1string2

    It looks like

    string1
    string2

    How can I get rid of the newline? Could I use strlen to find the length THEN use a function to replace the last character (which would be the newline ? or would it have a NULL after it?)

    I am using strcat to join the strings together.

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Look at this thread: http://cboard.cprogramming.com/showthread.php?t=80553

    It's like an entire 6 threads below yours so I understand how you didn't find it. Or the FAQ that's pointed out in the thread.
    If you understand what you're doing, you're not learning anything.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    http://faq.cprogramming.com/cgi-bin/...&id=1043284385
    If you carried on reading, you would see how to remove the \n
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    18
    Thank you that helped me alot.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  2. Compile Error that i dont understand
    By bobthebullet990 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 09:19 AM
  3. Replies: 4
    Last Post: 03-03-2006, 02:11 AM
  4. string manipulation problem
    By csj561 in forum C++ Programming
    Replies: 3
    Last Post: 03-18-2005, 11:11 PM