N
Nilbert Nullingsworth
Hey guys, a question.
When I have a function that takes a u_char[] as an argument, you would
usually do it like this:
u_char a[3] = {'a', 'b', 'c'};
functionThatRequiresUChar(a);
But what if you don't know how big the u_char will be at compile time?
I tried doing something like this:
int len;
cin >> len;
u_char a[len];
But the compiler won't do that as it says it can't allocate memory of
an unknown size.
I tried doing this:
int len;
cin >> len;
u_char *a;
a = new u_char[len];
functionThatRequiresUChar(a);
And it compiles. However, is this the right way to do it?
Will the function be able to tell I have made the u_char doing that
(apparently) non-standard way?
Or do I have to do it like
functionThatRequiresUChar(*a);
?
Thanks for any help.
When I have a function that takes a u_char[] as an argument, you would
usually do it like this:
u_char a[3] = {'a', 'b', 'c'};
functionThatRequiresUChar(a);
But what if you don't know how big the u_char will be at compile time?
I tried doing something like this:
int len;
cin >> len;
u_char a[len];
But the compiler won't do that as it says it can't allocate memory of
an unknown size.
I tried doing this:
int len;
cin >> len;
u_char *a;
a = new u_char[len];
functionThatRequiresUChar(a);
And it compiles. However, is this the right way to do it?
Will the function be able to tell I have made the u_char doing that
(apparently) non-standard way?
Or do I have to do it like
functionThatRequiresUChar(*a);
?
Thanks for any help.