Thread: main function arguments

  1. #1
    Registered User
    Join Date
    Sep 2003

    main function arguments

    my main fucntion is declared as follows:

    int main(int argc, char **argv)

    the name of the program is crypt.exe .. and the two arguments are supposed to be p and q which are integers...

    argv[1] is p and argv[2] is q.. i got that much.. but i need to declare a new int so that i can make the int types the same number as what the chars are... so if i type: crypt 5 12 ..

    i can have int *p and int*q equal to 5 and 12 .. I tried so many different things and it kept spitting back big numbers, can anyone else help?


  2. #2
    Join Date
    Sep 2003
    If I'm getting this straight, you want to pass two values to your program and then create arrays of those sizes:
    #include <cstdlib>
    int main(int argc, char *argv[]) {
      int *p;
      int *q;
      if (argc == 3) {
        p = new int[ std::atoi(argv[1]) ];
        q = new int[ std::atoi(argv[2]) ];
    The information given in this message is known to work on FreeBSD 4.8 STABLE.
    *The above statement is false if I was too lazy to test it.*
    Please take note that I am not a technical writer, nor do I care to become one.
    If someone finds a mistake, gleaming error or typo, do me a favor...bite me.
    Don't assume that I'm ever entirely serious or entirely joking.

  3. #3
    Comment your source code! Lynux-Penguin's Avatar
    Join Date
    Apr 2002
    There's nothing about arrays in there...

    #include <iostream.h>
    #include <stdlib.h>
    int main(int argc, char* argv[])
      int p,q;
      if(argc>0 && argc<3)
      return 0;
    I hope that's what you wanted...

    from the looks of it, you're trying RSA encrption. A little piece of advice... the numbers get too big to handle in regular C so you might need a library that can handle these large numbers.

    Asking the right question is sometimes more important than knowing the answer.
    Please read the FAQ
    C Reference Card (A MUST!)
    Pointers and Memory
    The Essentials
    CString lib

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. doubt in c parser coding
    By akshara.sinha in forum C Programming
    Replies: 4
    Last Post: 12-23-2007, 01:49 PM
  2. Troubleshooting Input Function
    By SiliconHobo in forum C Programming
    Replies: 14
    Last Post: 12-05-2007, 07:18 AM
  3. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  4. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM
  5. Return Statement
    By Daveo in forum C Programming
    Replies: 21
    Last Post: 11-09-2004, 05:14 AM