C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 24th, 2004, 09:41 PM
The Phantom The Phantom is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Location: In the Dark City
Posts: 46 The Phantom User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via AIM to The Phantom
What is this??

What is this code for:
Code:
 int main(int argc, char* argv[])

Reply With Quote
  #2  
Old September 25th, 2004, 04:24 AM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 6
As I'm sure you already know the function main is the entry point into your program. The int before it shows that it returns an integer. Normally this would return to a function in your program but the return from main goes to the operating system. Generally main should just return 0 which means it exited successfully but you can return other codes for other situation.

The two arguments it takes int argc and char *argv[] refer to the commandline arguments specified to the program. argc holds the number of arguments (including the program's name) and argv holds the arguments as an array of arrays of characters. (A list of strings).

So if you were to run the program foo with the arguments "-a bar 2" then argc would be equal to 4 (3 arguments and the program name) and argv would contain ["foo", "-a", "bar", "2"] so you could do something like -

Code:
for (int i=0; i<argc; i++)
  cout << argv[i];


This would cause the program to dump the variables to the terminal.

Hope this helps,

-KM-

Reply With Quote
  #3  
Old September 25th, 2004, 08:32 AM
The Phantom The Phantom is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Location: In the Dark City
Posts: 46 The Phantom User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via AIM to The Phantom
k thanks i had to explain it to a friend but i didn't know how to.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > What is this??


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT