newbie question

This is a discussion on newbie question within the C Programming forums, part of the General Programming Boards category; I have an exam on C coming up and one of the past papers has the following question: we have ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    5

    newbie question

    I have an exam on C coming up and one of the past papers has the following question:

    we have this loop :

    Code:
    for( i = 0; i < 127 && (c=getchar()) != '\n'; i++)
            s[i] = c ;

    the question is:

    If the user types in a line of text at the keyboard and presses ENTER what statement must be placed after the for loop to ensure that the array s contains a properly teminated string containing exactly what the user just entered (excluding the newline)

    any help would be greatly appreciated

  2. #2
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    s[i] = '\0';

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stupid Newbie question
    By TimL in forum C++ Programming
    Replies: 4
    Last Post: 07-22-2008, 04:43 AM
  2. C prog newbie question
    By Draginzuzu in forum C Programming
    Replies: 1
    Last Post: 02-03-2003, 05:45 PM
  3. a stupid question from a newbie
    By newcomer in forum C++ Programming
    Replies: 4
    Last Post: 01-11-2003, 03:38 PM
  4. confusion with integers (newbie question)
    By imortal in forum C Programming
    Replies: 7
    Last Post: 12-06-2002, 03:09 PM
  5. newbie class templates question
    By daysleeper in forum C++ Programming
    Replies: 2
    Last Post: 09-18-2001, 09:50 AM

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