Thread: Taking int arguments with char?

  1. #1

    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
    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, 11:57 AM
  2. Replies: 16
    Last Post: 10-29-2006, 05:04 AM
  3. Replies: 14
    Last Post: 06-28-2006, 01:58 AM
  4. getting a headache
    By sreetvert83 in forum C++ Programming
    Replies: 41
    Last Post: 09-30-2005, 05: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