Thread: simple Array question.

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    60

    simple Array question.

    Is there a way to have the user type something into an array and then find out and display how many characters the user input into the array (i guess this would be the size of the array)?

    - I am just starting out in c++ so any suggestions are appreciated.

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    FAQ > How do I... (Level 1) > Get a line of text from the user/keyboard (C) ?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    60
    Ok, but how do I count how many letters the user input?

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Show us what you've got. (I'd use strlen, though.)
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Registered User
    Join Date
    Oct 2007
    Posts
    60
    I am still figuring out how to start the code. This is for a c++ class and we didn't learn some of the functions listed on that faq, so I think we should work mainly with arrays.

    Does anyone have a simple way of doing this/suggestions?

  6. #6
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Oops. I always default to C.

    http://faq.cprogramming.com/cgi-bin/...&id=1043284385

    And if you're having this much trouble posting a simple copy of that code with an attempt to work on this yourself, I'd guess you have to use something like a for loop to iterate through the string in search of the null character.

    Take a stab at it.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  7. #7
    Registered User
    Join Date
    Oct 2007
    Posts
    60
    I used that format and it works. But, is it possible to have exactly that but with an array with a maximum number of characters instead of a string? How would I do that?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hopefully simple question, input streams
    By dpro in forum C++ Programming
    Replies: 7
    Last Post: 03-09-2006, 01:59 PM
  2. Very simple question, problem in my Code.
    By Vber in forum C Programming
    Replies: 7
    Last Post: 11-16-2002, 03:57 PM
  3. simple array question
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 02-16-2002, 10:43 PM
  4. simple array question
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 12-03-2001, 04:46 PM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM