passing parameters to main

This is a discussion on passing parameters to main within the C++ Programming forums, part of the General Programming Boards category; I'm writing a little perl program that calls a c program. I want to pass a variable from perl into ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    12

    passing parameters to main

    I'm writing a little perl program that calls a c program. I want to pass a variable from perl into the c program. I tried it like this(in a very simplified example):

    in perl:
    @data=`Cprog.exe number`; #number is the varaible sent to C
    ...

    in C:

    int main(int argc, char* argv)
    {

    cout<<"Number is equal to: "<<argv[0]<<endl;
    return 0;
    }

    When I print out data in the perl program, it outputs that funny y character with two dots over it. None of my C books have anything on main's parameters, so I can't find help there. Any ideas?

  2. #2
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    Dude, this belongs in ether the C or the Genreal Disscusion boards, read the board's name careully that you are in right now.....See Plus Plus.....

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    Despite the comments, it is a c++ program (note the cout)

    > it outputs that funny y character with two dots over it
    This will be EOF (usually -1), cast to a char (usually 255)


    > int main(int argc, char* argv)
    Should be
    int main(int argc, char *argv[] )

    > cout<<"Number is equal to: "<<argv[0]<<endl;
    If you want to output the first parameter, it would be
    cout<<"Number is equal to: "<<argv[1]<<endl;

    > None of my C books have anything on main's parameters
    They're all crap books then - this is basic information.

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    12
    dude(quantizi), thanks for the advice...

    thanks salem, I'll give that a try. Two of my c++ (is that better quan?) books are from class and one is "core C++ a software engineering approach", I couldn't find the answers in there, but I just found exactly what you said to do in a reference book that I forgot I had. Thanks!

  5. #5
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    No problem....glad to help[/sarcasm]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing along function parameters
    By FlyingIsFun1217 in forum C++ Programming
    Replies: 16
    Last Post: 12-31-2007, 03:43 AM
  2. Passing a double array from main to another function
    By Loctan in forum C++ Programming
    Replies: 2
    Last Post: 01-04-2005, 04:19 PM
  3. passing 2d arrays as parameters
    By aldajlo in forum C Programming
    Replies: 13
    Last Post: 10-10-2004, 12:46 PM
  4. Passing Parameters in Visual C++
    By UnclePunker in forum C++ Programming
    Replies: 4
    Last Post: 09-24-2003, 08:45 AM
  5. passing a file name to main()
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 09-06-2001, 04:08 PM

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