Could anyone please tell me how to make a command where i can add parameters. I've searched on the internet but I dont get it!
Can anyone help?
Thanks
P.S I've just been doing this for a week, and Im a kid so be instructive and sympathetic.
:-)
7 1376
Could anyone please tell me how to make a command where i can add parameters. I've searched on the internet but I dont get it!
Can anyone help?
Thanks
P.S I've just been doing this for a week, and Im a kid so be instructive and sympathetic.
:-)
Do you know about argc and argv? They're both the parameters to the main function: -
int main(int argc, char* argv[]) {
-
...
-
}
-
The first parameter equals the number of parameters supplied to you program
plus one. argv[0] equals the name of your program itself. The other argv[i] equal
the parameter i supplied to your program. Do this for starters: -
#include <stdio.h>
-
-
int main(int argc, char* argv) {
-
int i;
-
printf("argc= %d\n", argc);
-
for (i= 0; i < argc;i++)
-
printf("argv[%d]= %s\n", i, argv[i]);
-
return 0;
-
}
-
kind regards,
Jos
thanks a lot for your help. I'm making mathematical programs. I've got loads, but I just wanted to compile them all into 1 program.
I tried simulating parameters using IF and ELSE IF etc.
but it was a nightmare
thanks a lot for your help. I'm making mathematical programs. I've got loads, but I just wanted to compile them all into 1 program.
I tried simulating parameters using IF and ELSE IF etc.
but it was a nightmare
If you have multiple functions, I'd recommend either making them methods of a class, or just making them functions in your main (depending on how big your main is and how big your functions are). Then you can call them as desired passing whatever values you want. This is also a good way to abstract them.
thanks a lot for your help. I'm making mathematical programs. I've got loads, but I just wanted to compile them all into 1 program.
I tried simulating parameters using IF and ELSE IF etc.
but it was a nightmare
You bet; if you're programming in C++ you'd better build an abstract class
that can give it's name and the number of arguments it needs. Then populate
a map with names and concrete subclasses of that abstract class.
Your main() function then expects the name of the 'function' followed by its
arguments. Find the name in the map and invoke some method of the class
given the correct number of arguments.
kind regards,
Jos
that parameter code snippet you gave me above...it kept coming up with a system.AcessViolationError thing.
It kept closing after printing on the screen
Argc=1
whats an abstract class!
That sounds like a fantastic question for google, ask, yahoo, etc...
A topic like that is so broad and general that it would be difficult if not impossible to convey to you in this format. Try researching it.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Zlatko Matić |
last post by:
Let's assume that we have a database on some SQL server (let it be MS SQL
Server) and that we want to execute some parameterized query as a
pass.through query. How can we pass parameters to the...
|
by: Mark |
last post by:
I created a test to check the execution time difference between executing a
SQL Server stored procedured using explicit parameters versus not. In one
case I created new SqlParameters in the code,...
|
by: Tim::.. |
last post by:
Can someone tell me a better way or give me a link that shows a better way to
create large numbers of SQL parameters...
Example... A better way to write this code!
<code>
Sub...
|
by: cody |
last post by:
I got a similar idea a couple of months ago, but now this one will require
no change to the clr, is relatively easy to implement and would be a great
addition to C# 3.0 :)
so here we go..
To...
|
by: John Friedland |
last post by:
My problem: I need to call (from C code) an arbitrary C library
function, but I don't know until runtime what the function name is,
how many parameters are required, and what the parameters are. I...
|
by: Hexman |
last post by:
Hello All,
Well I'm stumped once more. Need some help. Writing a simple select and update program using VB.Net 2005 and an Access DB. I'm using parameters in
my update statement and when trying...
|
by: pamelafluente |
last post by:
Hi guys,
In the past I have used several time optional parameters in my
function.
But Now I am more inclined to think that they are more dangerous than
useful, and probably better to be...
|
by: John Kotuby |
last post by:
Hi all,
I am working on porting an application from VB6 to VB.NET 2003 and am
running into some problems. When declaring and populating the parameters for
a SQL Stored Procedure by using the...
|
by: Xah Lee |
last post by:
In this article, i explain how the use of bit masks is a hack in many
imperative languages.
Often, a function will need to take many True/False parameters. For
example, suppose i have a function...
|
by: Jared Grant |
last post by:
I am trying to find the value from some output parameters from a stored procedure. I have tried several different methods but somehow cannot get it to work. here is my source code:
dim dr as...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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...
|
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...
| |