I have some inherited code and a function which takes a character array as a parameter.
typedef char myString[256];
void MyFunc(myString param)
{
int i;
for (i = 0; i < 256; i++)
{
if (param[i] ....
I would like to make this more efficient and pass a pointer to the char array:
void MyFunc(myString *param)
{
int i;
for (i = 0; i < 256; i++)
{
if (*param[i] <========= Thsi is wrong
When I try to reference the array elements, I get the wrong value, so obviously something is wrong with my pointer dereferencing. It has been a while since I coded in C, so I can’t see the obvious mistake.
Can someone please point it out?
You probably don’t want to pass it via a pointer; when you use the type in the argument, it becomes a pointer anyway, and second level of indirection is less efficient.
If you do use the ‘pointer to an array’ notation, then you need parentheses to get the precedence correct: