String Manipulation Problem

This is a discussion on String Manipulation Problem within the C Programming forums, part of the General Programming Boards category; I have a string right, which has data put into it from a file I am reading from. It reads ...

  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,163
    Look at this thread: strcmp doesn't work with fgets.

    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,490
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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, 10: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, 01:11 AM
  4. string manipulation problem
    By csj561 in forum C++ Programming
    Replies: 3
    Last Post: 03-18-2005, 10:11 PM

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