473,399 Members | 4,254 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,399 software developers and data experts.

Parameters

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.

:-)
Aug 14 '07 #1
7 1376
JosAH
11,448 Expert 8TB
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:

Expand|Select|Wrap|Line Numbers
  1. int main(int argc, char* argv[]) {
  2.    ...
  3. }
  4.  
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:

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3. int main(int argc, char* argv) {
  4.    int i;
  5.    printf("argc= %d\n", argc);
  6.    for (i= 0; i < argc;i++)
  7.       printf("argv[%d]= %s\n", i, argv[i]);
  8.    return 0;
  9. }
  10.  
kind regards,

Jos
Aug 14 '07 #2
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
Aug 14 '07 #3
sicarie
4,677 Expert Mod 4TB
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.
Aug 14 '07 #4
JosAH
11,448 Expert 8TB
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
Aug 14 '07 #5
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
Aug 14 '07 #6
whats an abstract class!
Aug 14 '07 #7
sicarie
4,677 Expert Mod 4TB
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.
Aug 14 '07 #8

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

Similar topics

7
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...
2
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,...
4
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...
14
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...
18
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...
2
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...
12
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...
1
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...
0
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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:
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...
0
jinu1996
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...
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...

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.