Tell a friend
Link to us
Bookmark Us
Total Members
      Members: 87081
Sitemap Forum Chat
 
C++ Home
C++ Members (4396)
C++ Member Articles ( 19 )
C++ Discussion (116)
C++ Q & A ( 4 )
- C++ Ask Question
- C++ Questions
- C++ Unanswered Questions
C++ Resources
C++ Source Code (98)
C++ Articles (82)
C++ Blogs (0)
C++ Jobs (0)
C++ Components (11)
C++ Books (2)
C++ Websites (45)
C++ News (49)

 
Resource Directory
ODBC (0)
Source Code (0)

 
GROUP INFO
Members: 4396
Access Type: Anyone can join

 
GROUPS
.NET
ASP.NET
.NET
C#
ASP
Visual Basic
Java
Java
JSP
EJB
Other
Delphi
C++
Ajax
UML
JavaScript
PHP
Web Design
Web Hosting
SQL Server
Oracle
Project Management
More Groups

 
LEARNING CENTER
TUTORIALS
.NET
.NET Tutorial
ASP Tutorial
ASP.NET Database Tutorial
ASP.NET Development Tips
ASP.Net Security,Internationalisation And Deployment
ASP.NET Server Controls Tips
ASP.NET Tutorial
C Sharp Tutorial
LINQ Tutorial
Web Development
Flex Tutorial
HTML Tutorial
Javascript Tutorial
Learn AJAX Tutorial
PHP Tutorial
Software Development
Database Tutorial
SQL Tutorial
UML Tutorial
Java
Ant Tutorial
EJB 3 Tutorial
Grails Tutorial
Hibernate Tutorial
Java 1.6 Tutorial
Java Tutorial
Java Web Component Tutorial
Java XML Tutorial
JDBC Tutorial
JDK1.5 Tutorial
JSF Tutorial
JSP And J2EE Design Tutorial
JSP Tutorial
Service-Oriented Architecture (SOA) Tutorial For Managers
Spring Tutorial
Struts Tutorial
Tomcat Tutorial

RESOURCES
Q & A (531 )
Source Code (3276 )
Articles (365 )
Books (373 )
Components (1647 )
News (898 )
Websites (1208 )

SUBMISSIONS
Submit Article
Submit Website
Submit News
Submit Source Code
Submit Component

COMMUNITY
Authors
Members Directory
Discussion Forum
Chat

SITE
About Us
Sitemap
Search
Contact Us
Feedback
Tell a Friend
Advertise

 

Home > C++ > Member Articles > Algorithms >
 

Basics Of Argc And Argv


  Author : tac_onin
  Date Published : 04/5/2002
  Rating No Rating
  Accessed : 5138
   tac_onin

argc and argv are two arguments that are often used in C++ programs. argc is an int and argv is a char. argc holds the number of arguments starting with 0. argv holds the list of arguments, the 0 argument is always the program. To obtain an argument from argv, you do argv[argument number]; Here is an example program :


/* C:folderarg.exe */
/* This program demonstrates argc and argv. */
#include /* Include stdio.h for the printf() function. */
using namespace std; /* Declare scope. */
int main(int argc, char *argv[]); /* Prototype the main() function as an int, because it returns an integer. This may not be necessary on your compiler. */
int main(int argc, char *argv[]) /* Put the argc and argv into the main() function. argc is the number of arguments, and argv is the list of arguments */
{ /* Begin the main() function. */
for (int count = 0; count < argc; count ++) /* Initialize a for loop to print the list of arguments. We start with 0. */
{ /* Begin the for loop. */
printf("%s", argv[count]); /* Use the printf() function to print arguments to the screen. %s represents a string of characters. */
} /* End the for loop. */
return 0; /* Return the integer value 0 to end the main() function. */
} /* End the main() function. */

If you dragged a C:folderfile.ext on to this program's icon, it would output :

C:folderarg.exe
C:folderfile.ext

but if you double clicked it, it would output :

C:folderarg.exe

These two arguments can be useful when making an interpreter or some program to analyze files of a specific type. I used this code when I created the Broccolidog & Cauliflowerdog Script scripting language. There are many more uses for this code, and it is free.



 
   Add Comment  Printer Friendly
   View All Comments  Email to a friend
   Add to my Favourites  Report Bad Submissions  Submit Feedback
   Rating Download PDF version
 
                 Click each image to add
this page to each site.
 
Related Articles of C++
Random Articles    -     Next Article
 
 
 
Comments Available

    No comment available at the moment.Be the first one to make a comment

 
 
 
 
 
Welcome Guest Signup
Member's Panel
EMAIL
PASSWORD
Forgot your password?
New User? Click Here!
 
Resend Activation Email!

SEARCH
 



 
 
 
 
 


Home | Login | About Us | Contact Us | Privacy Policy | Advertising | Feedback Please

Warning: Unknown(): write failed: Disk quota exceeded (122) in Unknown on line 0

Warning: Unknown(): Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp) in Unknown on line 0