Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > command line arguments

Reply
Thread Tools

command line arguments

 
 
Ashe Corven
Guest
Posts: n/a
 
      05-08-2004
i need help pretty bad for this

from the command line

>csend string1 4233 "string2"


how can i copy string1, or string2 to a char* or a string.


for argument 4 (string2)

char temp[256];
strcpy(temp, argv[4]);

this doesn't work
------------
int i;
char temp[256];
for(i=1; argv[4][i] != '"'; ++i)
{
temp[i] = argv[4][i];
}
temp[i] = '\0'

neither does this - gives a seg fault on this line
for(i=1; argv[4][i] != '"'; ++i)

how do i do it. and why don't these techniques work


 
Reply With Quote
 
 
 
 
David Harmon
Guest
Posts: n/a
 
      05-08-2004
On Sat, 08 May 2004 15:42:03 GMT in comp.lang.c++, "Ashe Corven"
<cfitzgib@@bigpond.net.au> wrote,
>from the command line
>
>>csend string1 4233 "string2"

>
>how can i copy string1, or string2 to a char* or a string.
>
>
>for argument 4 (string2)
>
>char temp[256];
>strcpy(temp, argv[4]);


Main reason being that string2 is argv[3] ?


int main(int argc, char *argv[])
{
cout << "argc = " << argc << '\n';
for(int argx = 0; argx < argc; argx++) {
cout << "argv[" << argx << "] = \"" << argv[argx] << "\"\n");
}
return 0;
}

 
Reply With Quote
 
 
 
 
Ashe Corven
Guest
Posts: n/a
 
      05-08-2004
oh ****
haha
"David Harmon" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Sat, 08 May 2004 15:42:03 GMT in comp.lang.c++, "Ashe Corven"
> <cfitzgib@@bigpond.net.au> wrote,
> >from the command line
> >
> >>csend string1 4233 "string2"

> >
> >how can i copy string1, or string2 to a char* or a string.
> >
> >
> >for argument 4 (string2)
> >
> >char temp[256];
> >strcpy(temp, argv[4]);

>
> Main reason being that string2 is argv[3] ?
>
>
> int main(int argc, char *argv[])
> {
> cout << "argc = " << argc << '\n';
> for(int argx = 0; argx < argc; argx++) {
> cout << "argv[" << argx << "] = \"" << argv[argx] << "\"\n");
> }
> return 0;
> }
>



 
Reply With Quote
 
Francis Glassborow
Guest
Posts: n/a
 
      05-08-2004
In message <fd7nc.27672$(E-Mail Removed)>, Ashe Corven
<cfitzgib@?.net.au.invalid> writes
>i need help pretty bad for this
>
>from the command line
>
>>csend string1 4233 "string2"

>
>how can i copy string1, or string2 to a char* or a string.
>
>
>for argument 4 (string2)
>
>char temp[256];
>strcpy(temp, argv[4]);
>
>this doesn't work
>------------
>int i;
>char temp[256];
>for(i=1; argv[4][i] != '"'; ++i)
>{
> temp[i] = argv[4][i];
>}
>temp[i] = '\0'
>
>neither does this - gives a seg fault on this line
>for(i=1; argv[4][i] != '"'; ++i)
>
>how do i do it. and why don't these techniques work
>
>


The four command line arguments are pointed to by:
argv[0] // pointer to the name of the program
argv[1] // pointer to string1
argv[2] // pointer to 4233
argv[3] // pointer to string2

Remember that in C (and C++) we count from 0.


--
Francis Glassborow ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run Unix shell command $ parse command line arguments in python rkoida@yahoo.com Python 4 04-23-2005 04:42 AM
include for command line arguments Ian Malone C++ 8 02-18-2005 05:04 PM
Documentation on command line arguments to perl Peter Kay Perl 1 05-18-2004 01:27 AM
How to hide command line arguments in a windows application SC C++ 2 05-05-2004 10:06 AM
Parser for command line arguments? Ahmed Moustafa Java 0 08-21-2003 05:21 AM



Advertisments