D
Dawn Minnis
Hey guys
If I have a program (see codeSnippet1) that I compile to be called test.o
Then run it as test.o n n 2 3 4
I want the code to be able to strip out the two characters at the start
(always going to be 2) and store them as characters. But I can't seem to
get it to work because it is a pointer to a vector of characters.
However, if I only run with integer arguements and use codeSnippet2 it works
fine and they convert nicely to integers.
So therefore, I want to ammend my nice little loop to start converting to
integers from x=2 onwards. Which I can do fine. But how do I get the two
characters that are actual characters to be stored as characters. It
doesn't seem to be straightforward - or am I missing something stupidly
obvious?
codeSnippet1
int main(int argc, char *argv[])
{
int x;
char a, b;
/*Need these two lines to work ie get the first two arguements stored as
single characters for use elsewhere*/
a = argv[0];
b = argv[1];
/**************************/
}
codeSnippet2
int main(int argc, char *argv[])
{
int x;
int params[10];
for(x=0; x<argc; x++)
{
params[x] = atoi(argv[x]);
}
}
If I have a program (see codeSnippet1) that I compile to be called test.o
Then run it as test.o n n 2 3 4
I want the code to be able to strip out the two characters at the start
(always going to be 2) and store them as characters. But I can't seem to
get it to work because it is a pointer to a vector of characters.
However, if I only run with integer arguements and use codeSnippet2 it works
fine and they convert nicely to integers.
So therefore, I want to ammend my nice little loop to start converting to
integers from x=2 onwards. Which I can do fine. But how do I get the two
characters that are actual characters to be stored as characters. It
doesn't seem to be straightforward - or am I missing something stupidly
obvious?
codeSnippet1
int main(int argc, char *argv[])
{
int x;
char a, b;
/*Need these two lines to work ie get the first two arguements stored as
single characters for use elsewhere*/
a = argv[0];
b = argv[1];
/**************************/
}
codeSnippet2
int main(int argc, char *argv[])
{
int x;
int params[10];
for(x=0; x<argc; x++)
{
params[x] = atoi(argv[x]);
}
}