473,395 Members | 1,937 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

parameters to main

12
hi
I wrote a program and that should takes some parameters when it is executed
like that

program.exe /s

and I wanna write if statements according to parameters but i could not.
for instance;

Expand|Select|Wrap|Line Numbers
  1.  
  2. #include<stdio.h>
  3.  
  4. main(char c)
  5. {
  6. if(c=='s')
  7. func1();  // appropriate function
  8. else 
  9. func2();
  10.  
  11. return 0;
  12. }
  13. I think question is simple.I try to take some parameters from main but my prog. could not work i do something wrong
  14.  
  15. please help me 
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
Nov 11 '06 #1
1 2204
Banfa
9,065 Expert Mod 8TB
main has the following prototype

int main(int argc, char **argp)
{
// Code here
}

You are not at liberty to change it.

argc and argp however allow you access to the command line. argp is a pointer to an array of char pointers (some people like to write it as char *argp[] to reflect this). argc is the size of this array. The only thing you can be sure of is that

argp[argc] == NULL

this is garunteed by the standard for a conforming implementation.

However normally

argp[0] is the name of the program running

and

argp[1] ... argp[argc-1] are the other items appearing on the command line split of white space characters.

In your example

argc = 2
argp[0] = "program.exe"
argp[1] = "/s"
Nov 11 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

40
by: Sonia | last post by:
Hi, Please look at the following code. This is a simple program for a game of craps - very basic. I have declared the gameStatus as global variable. I was wondering if there is a better way of...
3
by: Steve | last post by:
Visual Studio 2003 / C# My application has 1 main form. On this form is a treeview object down the left hand edge and a status bar along the bottom. That is all. The tree view acts as my menu...
8
by: A.M | last post by:
Hi, Are string parameters in functions by refrence or by value ? Thanks, Ali
3
by: C# Learner | last post by:
Note ---- Please use a fixed-width font to view this, such as Courier New. Problem
1
by: Mikey G | last post by:
Hi, I created a simple VB.NET 2003 application through Visual Studio that connects to a MySQL database and loads a table into a Dataset, and then displays that table information in a DataGrid on a...
3
by: Adam Hartshorne | last post by:
What is named parameter mechanism? Any ideas? I am looking through some code and there is a comment saying "VC++ has trouble with the named parameters mechanism", which i have no idea what this...
1
by: kplkumar | last post by:
I am trying to get the method and the parameters passed to that method from the stackTrace. My code is, private void GetExecutingMethodInfo() { StackTrace trace = new StackTrace(false); ...
7
by: Kenneth Brody | last post by:
The recent thread on "query about main()" got me thinking... As I recall, calling a function with the wrong parameters causes undefined behavior. (These all assume that no prototype of foo()...
3
by: Alan T | last post by:
I would like to create an exe file with the option that the user to input parameters, how do I do that?
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.