Array boundary and error checking

This is a discussion on Array boundary and error checking within the C++ Programming forums, part of the General Programming Boards category; Having a couple fairly simple problems (but I'm lost nonetheless): I have a class consisting of something like this: class ...

  1. #1
    JKI
    JKI is offline
    Registered User JKI's Avatar
    Join Date
    Sep 2003
    Posts
    19

    Array boundary and error checking

    Having a couple fairly simple problems (but I'm lost nonetheless):

    I have a class consisting of something like this:

    class myclass

    char a[60];
    char b[60];
    int c;
    int d;
    float e;
    float f;

    .....

    The input to fill the variables are entered via keyboard.

    I use cin.getline(obj.a, 60); for the arrays, but user can over run boundaries. How can I control this?

    Also, when error checking the int's and float's (cin >> obj.c;) how do I stop a char input?

    Any help much appreciated.

    ::Jazz
    Last edited by JKI; 09-18-2003 at 07:24 AM.

  2. #2
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    >>I use cin.getline(obj.a, 60); for the arrays, but user can over >>run boundaries. How can I control this?

    you can dynamically allocate an array of words.

    Also, when error checking the int's and float's (cin >> obj.c how do I stop a char input?

    you can check input one by one and check if it is a digit.

    axon

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  3. #3
    JKI
    JKI is offline
    Registered User JKI's Avatar
    Join Date
    Sep 2003
    Posts
    19
    Originally posted by axon
    >>I use cin.getline(obj.a, 60); for the arrays, but user can over >>run boundaries. How can I control this?

    you can dynamically allocate an array of words.

    Also, when error checking the int's and float's (cin >> obj.c;) how do I stop a char input?

    you can check input one by one and check if it is a digit.

    axon
    Appreciate the quick reply!

    I actually tried both. (Using dynamic arrays within the class, and getline to "parse" in the function call; and isdigit() for the error checking.)

    My syntax is probably bad.

    I'll have a few more go's at it... see if I can't get the melon screwed on straight. If I can't make it right... I'll be back, LOL.

    Thanks again:: Jazz

Popular pages Recent additions subscribe to a feed

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