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

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




Argc

 
Reply to this topicStart new topic

Argc, arguments

C++programming
7 May, 2008 - 06:45 AM
Post #1

New D.I.C Head
*

Joined: 29 Apr, 2008
Posts: 2

I understand that argc refers to the number of arguments passed to the program. I do not understand however, how to use this. I'm doing a mad lib program and I can not find anything really useful or relevant to what I am suppose to incorporate in the program. Do you always have to use it this way

cpp
 int main(int argc, char* argv[]) { 
cout << "argc = " << argc << endl;
for(int i = 0; i < argc; i++)
cout << "argv[" << i << "] = " << argv[i] << endl;
return 0;
}

with the i's? The example he showed us in class did not have that in it.

Any feedback would be greatly appreciated!
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Argc
7 May, 2008 - 10:10 AM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,226



Thanked: 39 times
Dream Kudos: 25
My Contributions
i is simply an integer variable being used as a loop counter. the code you have above will loop through the argument list and print them.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/2/08 11:37PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month