Thread: read line

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    just so your prog doesn't crash and burn
    Code:
        while ((ch=getchar()) && (ch != '\n'))  // while( ((ch = getchar()) != '\0' ) &&  (ch != '\n' ))
        {    
               if(i < (n - 1) )   //assuming n = 50; prevent run-time segmentation fault
                   str[i++]=ch;
        }
    edit: after re-consideration, 'if(i < n)' will suffice granted n = 50
    Last edited by misplaced; 12-24-2004 at 10:00 AM.
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

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