Thread: read line

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    26
    I don't understand why you use sizeof as argument, and why in this line if (i < (n - 1)) you need n-1?

    Thanks.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >I don't understand why you use sizeof as argument
    sizeof str evaluates to 10. It's a nice easy way to pass the correct size of an array of char even if you decide to change the size for further testing.

    >and why in this line if (i < (n - 1)) you need n-1?
    If you allowed n characters to be read then there wouldn't be any room left for the null character that terminates a string.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. "sorting news" assignment
    By prljavibluzer in forum C Programming
    Replies: 7
    Last Post: 02-06-2008, 06:45 AM
  2. OPen a file and read it from the last line
    By c_geek in forum C Programming
    Replies: 14
    Last Post: 01-26-2008, 06:20 AM
  3. easy Q -> read a whole line from file
    By paperbox005 in forum C++ Programming
    Replies: 3
    Last Post: 09-27-2004, 03:58 PM
  4. Read each line of text file.
    By Mithoric in forum C++ Programming
    Replies: 1
    Last Post: 06-25-2003, 11:53 AM
  5. Greenhand want help!
    By leereg in forum C Programming
    Replies: 6
    Last Post: 01-29-2002, 06:04 AM