473,397 Members | 2,084 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,397 software developers and data experts.

C++ arguments

Hi, I'm a (very) new programmer to C++

I was trying to make a simple (small as possible!) program that would run the arguments as a command line with system()

For example:

starter.exe notepad.exe c:\boot.ini

would preform the same action as:
Expand|Select|Wrap|Line Numbers
  1. system("start notepad.exe c:\boot.ini");

However I can't seem to figure out how to get the 2d array given to main() into one big array (one entry after another - think argv[n] + argv[n+1] + arg[n+2] and so on. The most I can do is get the first "argument" (in reality I want EVERYTHING after my .exe to be one argument) to system().

system() wants a char array, so strings are out (as far as I understand - very little). It also most definatly doesn't want an array of char arrays.

Really I want to take each element of argv[] and put them into a 1-dimensional char array one after the other (inserting the spaces that get removed when the OS does it's voodoo to the arguments), call it argx, and use system("start " + argx); (providing system() doesn't barf at that syntax)


The reasoning behind this requirement is I'm trying to run a large .NET program from within a legacy DOS program with very limited resources (using "start" doesn't work, but using an additional intermediary gets around the problem.)
Dec 17 '06 #1
1 2462
Banfa
9,065 Expert Mod 8TB
OK 2 methods for you.

You sound like you are semi familiar with strings so use a string to create your string, then use the member function string::c_str() to return a pointer to an array of characters containing the string.

Alternitively us the C standard library functions

strcpy(...)
strcat(...)

To copy all the arguments into a single string. In order to make sure the string is long enough you should really calculate how much space you need and allocate the memory use malloc. The required space will be

sum of the lengths of all arguments + number of arguments

the length of a single argument can be calculated using strlen(...)


However initially (and may be alternitively) just use a very large array that is unlikely to be exceeded.
Dec 19 '06 #2

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

Similar topics

9
by: Chuck Anderson | last post by:
I have a function with 7 inputs. The last three have default values. I want to call that function specifying the first four, skip two and then specify the last. I thought I could write this...
9
by: Matt Eberts | last post by:
Sorry, bad title. Anyway, is there a way to pass the arguments to an object instantiated via a constructor using the arguments object and have it expanded, so to speak, so that it doesn't appear as...
6
by: Melkor Ainur | last post by:
Hello, I'm attempting to build an interpreter for a pascal-like language. Currently, I don't generate any assembly. Instead, I just build an abstract syntax tree representing what I've parsed...
21
by: dragoncoder | last post by:
Consider the following code. #include <stdio.h> int main() { int i =1; printf("%d ,%d ,%d\n",i,++i,i++); return 0; }
41
by: Telmo Costa | last post by:
Hi. I have the following code: -------------------------------------- function Tunnel() { //arguments(???); } function Sum() { var sum = 0; for (i=0; i<arguments.length; i++) sum +=...
9
by: Csaba Gabor | last post by:
Inside a function, I'd like to know the call stack. By this I mean that I'd like to know the function that called this one, that one's caller and so on. So I thought to do: <script...
7
by: sfeher | last post by:
Hi All, Is there a way to preserve the arguments across functions? I have: <script> function myFirstFunction() { // arguments = 'param1'
36
by: Pacific Fox | last post by:
Hi all, haven't posted to this group before, but got an issue I can't work out... and hoping to get some help here ;-) I've got a base object that works fine with named arguments when called...
7
by: VK | last post by:
I was getting this effect N times but each time I was in rush to just make it work, and later I coudn't recall anymore what was the original state I was working around. This time I nailed the...
2
ADezii
by: ADezii | last post by:
When a call is made to a Sub or Function Procedure, you can supply Arguments in the exact order they appear in the Procedure's definition, or you can supply them in any position by name. To...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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.