char* argv[]

char* argv[]

Post by goodTweeti » Sat, 21 Jun 2008 04:35:31


I need to test a function that has a signature similar to a typical
main:

int f1(int argc, char* argv[]);

Having trouble setting up the array of string pointers to send. Just
want to send in 3 strings but

int main(int argc, char* argv[])
{
char * s[] ={"123", "456", "789"} ;
f1(3, s);
}

does not seem to work. I only see first string.


Thanx,

gtb
 
 
 

char* argv[]

Post by Victor Baz » Sat, 21 Jun 2008 04:51:37


The types of the literals are "arrays of const char". While it is
allowed to initialise a pointer to a non-const char with a literal, you
should avoid it if at all possible. If your program does not attempt to
change the contents of those strings, consider passing an array of
pointers to const:

char const* s[] = ...


What do you mean by "see"? What does the 'f1' look like? BTW, in order
to pass the pointer to pointers to const char I *strongly* recommend
redeclaring 'f1' as

int f1(int argc, char const* argv[])

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

 
 
 

char* argv[]

Post by goodTweeti » Sat, 21 Jun 2008 05:08:02

>
> What do you mean by "see"?
When I stop the de *** in f1 the local variable only displayed the
first string.

What does the 'f1' look like? TW, in order >> to pass the pointer to pointers to const char I *strongly* recommend >> redeclaring 'f1' as >>

Actual signature for f1 is f1(int argc, char** argv). Signature is
dictated by Nucleus for registered functions to be called from a
shell. Was trying to do work out a little logic on V studio as it is
faster for development than the target system.

But since I am simulating I can use your suggestion of constant
pointers, which works fine for this effort will a little casting.

Thank you, Victor.
 
 
 

char* argv[]

Post by Igor Tande » Sat, 21 Jun 2008 05:37:56


The de *** doesn't know how large the array is. You have to tell it.
Put this in the Watch window:

argv,3

--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
 
 
 

char* argv[]

Post by Joe. » Sun, 22 Jun 2008 19:54:02

On Jun 20, 4:08m, goodTweetieBird < XXXX@XXXXX.COM >


You should initialize your argv with {"x", "y", NULL}; and call f1
with the actual argument number as the first argument.