reading in one character at a time

This is a discussion on reading in one character at a time within the C++ Programming forums, part of the General Programming Boards category; I need some help figuring out how to read in one character at a time into an array. For example ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    1

    reading in one character at a time

    I need some help figuring out how to read in one character at a time into an array. For example the word apple would be read in withe the a in position 0 the p in position 1 the p in position 2 the L in position 3 etc. i cannot figure this out any help is appriciated.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,328
    Read in with a loop and increment the index each time through. Stop the loop when you reach the end of the array or when the user enters some terminating character like a space or a newline.

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    When you don't know what to do try writing out the program in you native language like this:

    declare an array of char to hold input

    ask for input
    store user input into appropriate index of array
    repeat as many times as desired

    Then try to write code.
    You're only born perfect.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading Character at a time from a text file
    By Giania in forum C Programming
    Replies: 8
    Last Post: 02-25-2006, 02:17 PM
  2. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  3. reading 1 char at a time
    By krappykoder in forum C++ Programming
    Replies: 16
    Last Post: 10-23-2002, 11:12 AM
  4. I apologize. Good bye.
    By doubleanti in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 05-03-2002, 06:51 PM
  5. about reading character from a file
    By Abdi in forum C Programming
    Replies: 3
    Last Post: 05-03-2002, 11:25 AM

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