Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,615 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 964 people online right now. Registration is fast and FREE... Join Now!




int argc, char *argv[]?

 
Reply to this topicStart new topic

int argc, char *argv[]?, What do they mean?!?

Sn0wm4n
post 15 Jul, 2008 - 11:51 AM
Post #1


New D.I.C Head

*
Joined: 8 Jul, 2008
Posts: 11


My Contributions


I've been wondering for a while what these meant (the code in the title) but I finally get to a description of it in the book I'm using to learn C++ but it's hard to understand. Can someone tell me what these mean please?

CODE
#include <iostream>
#include <cstdlib>

using namespace std;

int main(INT ARGC, CHAR *ARGV[]){
.........
}
User is offlineProfile CardPM

Go to the top of the page

gabehabe
post 15 Jul, 2008 - 11:57 AM
Post #2


Working Girl.

Group Icon
Joined: 6 Feb, 2008
Posts: 5,439



Thanked 94 times

Dream Kudos: 2625

Expert In: ruling the world.

My Contributions


They're basically used when you want to be able to call your program from the command line.

In other words, think of those programs that you call from cmd...

You know how they take flags? example:
shutdown -s -t 1
-s and -t are flags, which are passed to the shutdown program. These are the args that main takes.

In other words, when you write a console program, you only really need int main ()

Hope this helps smile.gif
User is online!Profile CardPM

Go to the top of the page

jeronimo0d0a
post 15 Jul, 2008 - 12:00 PM
Post #3


D.I.C Head

**
Joined: 3 Mar, 2008
Posts: 141


My Contributions


argc is the number of command line arguements passed to the program which includes it's own name. the array argv is a vector containing them.
argv[0] will be the program name
argv[1] will be the first parameter
ie if I type edit somefile
edit, the program name is argv[0] and somefile is argv[1]
you check argc to make sure there actually are arguements
Hope this helps
Jeronimo
User is offlineProfile CardPM

Go to the top of the page

no2pencil
post 15 Jul, 2008 - 01:35 PM
Post #4


My fridge be runnin OH NOEZ!

Group Icon
Joined: 10 May, 2007
Posts: 6,351



Thanked 58 times

Dream Kudos: 2375

Expert In: Goofing Off

My Contributions


http://www.dreamincode.net/forums/showtopic30387.htm
User is online!Profile CardPM

Go to the top of the page

born2c0de
post 15 Jul, 2008 - 10:21 PM
Post #5


printf("I'm a %XR",195936478);

Group Icon
Joined: 26 Nov, 2004
Posts: 3,905



Thanked 34 times

Dream Kudos: 2800

Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions


QUOTE
int main(INT ARGC, CHAR *ARGV[]){

Keep in mind that int and char should be in lowercase.
User is offlineProfile CardPM

Go to the top of the page

nirvanarupali
post 15 Jul, 2008 - 10:41 PM
Post #6


D.I.C Foot

Group Icon
Joined: 1 Aug, 2007
Posts: 983



Thanked 2 times

Dream Kudos: 375
My Contributions


In addition of the posts above.

argc - stands for "argument count"
*argv[] - stands for "argument vector"

However you can change that to any variable names you want instead of using argc and argv.
User is offlineProfile CardPM

Go to the top of the page

polymath
post 16 Jul, 2008 - 08:12 AM
Post #7


D.I.C Regular

Group Icon
Joined: 4 Apr, 2008
Posts: 407



Thanked 4 times

Dream Kudos: 500
My Contributions


I didn't know that. Interesting...
User is offlineProfile CardPM

Go to the top of the page

kapax
post 16 Jul, 2008 - 12:05 PM
Post #8


New D.I.C Head

*
Joined: 2 Jul, 2008
Posts: 39



Thanked 1 times
My Contributions


Pity, I have nothing else to add sad.gif
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/23/08 02:54AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month