command line arguments

A

Ashe Corven

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)
{
temp = argv[4];
}
temp = '\0'

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

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

David Harmon

On Sat, 08 May 2004 15:42:03 GMT in comp.lang.c++, "Ashe Corven"
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;
}
 
A

Ashe Corven

oh shit
haha
David Harmon said:
On Sat, 08 May 2004 15:42:03 GMT in comp.lang.c++, "Ashe Corven"
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;
}
 
F

Francis Glassborow

Ashe Corven said:
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)
{
temp = argv[4];
}
temp = '\0'

neither does this - gives a seg fault on this line
for(i=1; argv[4] != '"'; ++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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,836
Latest member
login dogas

Latest Threads

Top