First of all argc should be initialized.
Wrong.... The variable argc is an integer initialized by the o/s before being sent to main() that's why it's aparameter of the function. All you have to do is use it...
P.S.
You're lucky I messed up on the like-dislike.
@OP:
Try changing Line 4 to simply ptr_a = a ;
Fbody
Posting Maven
2,930 posts since Oct 2009
Reputation Points: 833
Solved Threads: 393
> char a[10][25];
> char *ptr_a;
> ptr_a = (char *)a[10][25];
If you really want to do this with pointers, then it's
char a[10][25];
char (*ptr_a)[25];
ptr_a = a;
Then you should be able to use strcpy( ptr_a[index], argv[index] );
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
Thanks anyway.I deserve it.From what i know if you don't specify the number of arguments it wont' work.But then again .. maybe you're more well informed.Try to explain this better please.
Who are you addressing, and what are you talking about? Are you referring to argc and argv[]?
When you start a program, they give you the ability to send command-line arguments to the program. The value of argc is the count of the number of arguments and the values of argv[] are the contents/values of the arguments. Both are automatically initialized when the program starts.
The structure of argv is an array of char arrays. The contents of the sub-arrays are then analyzed to determine what the entered information is.
Fbody
Posting Maven
2,930 posts since Oct 2009
Reputation Points: 833
Solved Threads: 393
Ok i do know that.But when not intitializing argc , the parameter(s) passed at the command line won't be processed by the main program.It really makes sense since you array's index will be uninitialized.
The value of argc will always be >= 1 and argv will always have at least argc[0]. This is because the execute statement on the command line is considered the first argument.
Study passing arrays to functions a little more. It is allowable to leave the size of the first dimension of an array un-specified in a function's parameter list. Under these circumstances, when the function is called the size of the array is "dynamically" determined (sort of).
Fbody
Posting Maven
2,930 posts since Oct 2009
Reputation Points: 833
Solved Threads: 393
Ok . So why won't it work?I'm not disagreeing with you but that argument should.I can't see the purpose of the int argc argument in the main function if the os initializes the count automaticaly as you say.I mean .. i would not write an accesor for example , with an extra argument.Should it not be
int main (char* argv[])
supposing you're right ?
No, cause then argc flat out wouldn't exist. The values in argc and argv must be used together. The value contained in argc is comparable to an "arraySize" variable that woud typically be passed to any other function that accepts an array as a parameter and is used similarly.
The problem isn't with argc and argv[], it's with the assignment of the pointer to a[0][0] to ptr_a. It's completely unrelated. I think it best you start a new thread if you wish to pursue this topic further, we've already hijacked this thread enough.
Fbody
Posting Maven
2,930 posts since Oct 2009
Reputation Points: 833
Solved Threads: 393
char* argv[]
Is a pointer to an array of pointers.Or a pointer to an array of c character strings.If you don't initialize argc which should be the index for argv , pointing to a c string , then you wouldn'nt have an argument for the main function.
From what i saw .. declaring a data type does not by default initializes it with zero .. so in this case we do not have a string.Thus no argument.
I said start a new thread. I will not continue this here.
Fbody
Posting Maven
2,930 posts since Oct 2009
Reputation Points: 833
Solved Threads: 393