LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-09-2009, 01:20 PM   #1
yawningdog
LQ Newbie
 
Registered: Sep 2009
Posts: 19

Rep: Reputation: 0
semi-noob question


In college as a networking concentration, I took a few programming classes, mostly c++. Now I'm experimenting with a program in c that declares main like this.

Code:
int main(int argc, char *argv[])
In my programming classes and self study, I have never passed arguments to main. Can someone please explain the nature of these arguments? I suspect they have to do with command line arguments used when starting the program. If you need more info from me or if the question needs clarification, please let me know.

Thanks in advance.
 
Old 09-09-2009, 01:28 PM   #2
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by yawningdog View Post
they have to do with command line arguments used when starting the program.
Correct.

argv[0] is the command itself: the program name after whatever modification (path etc.) was done by the shell.

argv[1] is the first command line argument, etc.

argc is the count of them.

The best way to understand more is to write a simple C program that displays argv[0] through argv[argc-1] each on its own line of output. Then run that program with various input.
 
Old 09-09-2009, 01:31 PM   #3
mobinskariya
Member
 
Registered: Sep 2007
Location: Kerala, India
Distribution: ubuntu 10.04
Posts: 367

Rep: Reputation: 55
i think argc represents argument count and *argv[] represents the parameters passed..that means argv[1] is the first argument, argv[2] the second one and so on..
edit:as johnsfine stated argv[0] represents the command itself.

Last edited by mobinskariya; 09-09-2009 at 01:33 PM.
 
Old 09-09-2009, 01:52 PM   #4
yawningdog
LQ Newbie
 
Registered: Sep 2009
Posts: 19

Original Poster
Rep: Reputation: 0
Excellent. Thanks guys.
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux Semi-Noob Considering A Return to the Fold! SuperCoolAl Linux - Newbie 4 04-01-2006 01:26 PM
Semi-complicated Postfix/firewall config question mightyteegar Linux - Software 1 05-15-2005 10:12 AM
here comes the semi-noob ;-) bröggle LinuxQuestions.org Member Intro 2 08-18-2004 05:22 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration