Thread: Reading a string from the input which length isn't known.

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    76

    Reading a string from the input which length isn't known.

    Hi,
    I need to read a string from the input but I don't know the length of it. So I would like to read for example first 100 chars, then next 100 chars and so on, till '\n'. I though about using scanf() in such a form: scanf("%100s", buf); but I don't know the condition to check if the line is over. I can't wait for EOF from scanf() because I have a few lines to read. I don't want to read this string char by char. Can anyone help me?
    --
    Regards,
    apacz

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    A good one to use would be fgets(). If it read the whole string, the last character in the string will be a '\n' depending on what input you're using.
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can someone help me with these errors please code included
    By geekrockergal in forum C Programming
    Replies: 7
    Last Post: 02-10-2009, 02:20 PM
  2. Replies: 14
    Last Post: 01-18-2008, 04:14 PM
  3. Custom String class gives problem with another prog.
    By I BLcK I in forum C++ Programming
    Replies: 1
    Last Post: 12-18-2006, 03:40 AM
  4. Compile Error that i dont understand
    By bobthebullet990 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 09:19 AM