char array

This is a discussion on char array within the C++ Programming forums, part of the General Programming Boards category; ok i have to read in a string of numbers and chars into an array. i'm a little confused on ...

  1. #1
    Siciliano
    Guest

    Question char array

    ok i have to read in a string of numbers and chars into an array.
    i'm a little confused on how i should do this because the string will have single and also double digit numbers. so i can't use an array of chars right?
    can i do this using an array of ints?

    can i do this using the isdigit funtion?



    thanks




    Siciliano---

  2. #2
    Unregistered
    Guest
    if input needs to all be in the same array and input looks like this:

    smoothie 1.345 2567 a 14 345

    then you need to use a char array as a string and use getline() to read it all in at once. Here's one way:

    char dummmy[256];
    cout << "enter up to 255 letters, numbers and other chars" << endl;
    cin.getline(dummy, 256, '\n');
    cout << dummy << endl;

    If you elect to do this, then you should read up on getline() and the special issues associated with it's use.

  3. #3
    Something Clever ginoitalo's Avatar
    Join Date
    Dec 2001
    Posts
    187
    you can use an array of chars because a char is nothing but a number which when printed you are asking the compiler to output the character assigned to that number.

  4. #4
    Siciliano
    Guest
    cool thanks i was thinking of doing a process to the inputted string while it was being inputted, i don't know why i didn't think of doing it this way heheh
    I think i need a break from this program lols

    thanks



    Siciliano__

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 11-17-2008, 12:36 PM
  2. code condensing
    By bcianfrocca in forum C++ Programming
    Replies: 4
    Last Post: 09-07-2005, 10:22 AM
  3. code help required
    By Yobbo in forum C Programming
    Replies: 9
    Last Post: 09-03-2005, 12:15 AM
  4. Creating 2D arrays on heap
    By sundeeptuteja in forum C++ Programming
    Replies: 6
    Last Post: 08-16-2002, 12:44 PM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 10:48 AM

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