simple i/o question

This is a discussion on simple i/o question within the C++ Programming forums, part of the General Programming Boards category; right, i'm having problems with something stupid involving input and arrays. Code: char number[256]; cout << "enter a number" << ...

  1. #1
    n3v
    n3v is offline
    irregularly symmetrical n3v's Avatar
    Join Date
    Mar 2006
    Location
    Finland
    Posts
    67

    simple i/o and array question

    right, i'm having problems with something stupid involving input and arrays.

    Code:
        char number[256];
        cout << "enter a number" << endl;
        cin.getline(number,256);
        cout << "the number is" << endl;
             for (int i = 0;i > ???;i++) {
                 cout << number[i];
                 }
        cout << endl;
    what do i put in that red area to output the correct number?

    I know that if i put in 256, and if the number entered has less than 256 digits, then the program messes up. how can i figure out which units in the array are being used?

    i know this system isn't the way numbers are usually handled, but i'm doing something different involving very large numbers.
    Last edited by n3v; 04-06-2006 at 09:03 AM.

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,806
    Code:
    char number[256];
    cout << "enter a number" << endl;
    cin.getline(number,256);
    cout << "the number is" << endl;
    for (int i = 0;i < strlen(number);i++)
    {
        cout << number[i];
    }
    cout << endl;
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple Question!!
    By gameuser in forum C++ Programming
    Replies: 2
    Last Post: 06-06-2009, 06:42 PM
  2. Simple question about file I/O.
    By The7thCrest in forum C++ Programming
    Replies: 2
    Last Post: 02-04-2009, 05:15 PM
  3. simple I/O question
    By Mortissus in forum C++ Programming
    Replies: 7
    Last Post: 02-14-2005, 10:14 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM
  5. Overlapped I/O and Completion Port :: Winsock
    By kuphryn in forum Windows Programming
    Replies: 0
    Last Post: 10-30-2002, 05:14 PM

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