Taking int arguments with char?

This is a discussion on Taking int arguments with char? within the C++ Programming forums, part of the General Programming Boards category; How could I do something like: Code: int main(int argv, char **argv) to take a integer and char argument at ...

  1. #1
    _ Munkey01's Avatar
    Join Date
    Dec 2002
    Posts
    280

    Taking int arguments with char?

    How could I do something like:
    Code:
    int main(int argv, char **argv)
    to take a integer and char argument at the same time?

  2. #2
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    yep

  3. #3
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Command line will accept anything. Your integers will be stored in a as a c-string. Something like this would work:
    Code:
    int main(int argc, char **argv)
    {
       std::vector<int> numargs;
       for (int i = 0; i < argc; i++)
       {
            if (isdigit(argv[i][0])
                numargs.push_back(atoi(argv[i]));
       }
       std::cout << "Number of numeric arguments: " << numargs.size()-1 << std::endl;
       return 0;
    }
    Note: I just typed this up in the post box... there's probably errors.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 03-10-2008, 12:57 PM
  2. Replies: 16
    Last Post: 10-29-2006, 05:04 AM
  3. Replies: 14
    Last Post: 06-28-2006, 02:58 AM
  4. getting a headache
    By sreetvert83 in forum C++ Programming
    Replies: 41
    Last Post: 09-30-2005, 06:20 AM
  5. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 05:26 PM

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