assign the value of an array to a pointer c++
Hello @ all
I`m trying to do the following:
Code:
pTest->tst[0] = user_tst[0];
content of array is at this index 0x00
which doesn't work and stucks me to the following error:
error C2109: subscript requires array or pointer type.
the array comes from another file and is well defined(there) as it is also made external in the included header file.
I would be glad, if anyone could give me a hint or point me to correct direction.
Thanks for every read/help.
kox
here you are (code snippets)
thx for your reply
here is the relevant code:
file1 filling the array:
Code:
int tst_user[5];
int Fill()
{
char variable[] = "";
char * pch;
int i = 0;
printf("Enter desired Data in this style XX-XX-XX-XX-XX-XX : \n");
scanf("%s", &variable); //user input to address of variable
pch = strtok (variable, "- :");
while (pch != NULL)
{
printf("%s \n",pch); //control of splitting
sscanf (pch, "%x", &tst_user[i]); //filling
pch = strtok (NULL, "- :");
printf("array index %d = %#x \n",i, tst_user[i++]); //control array and add 1 to index
}
return 0;
}
.
.
.
Fill()
.
.
.
used header:
Code:
extern int tst_user;
file 2 assigning the array to the pointer:
Code:
pTest->tst[0] = tst_user[0]);
manually(static) assigning works just fine:
Code:
pTest->tst[0] = 0x00;
but this is not what i want.
The code is very long and the failure should be in the assignment or the interchange of the array itself.
i also tried it with:
Code:
pTest->tst[0] = static_cast<int>(tst_user[0]);
which gives the same error.
Thanks for reading/helping
kox
problem is in sharing the array itself
Hi @ all
@ caligalimus
Sorry, I have to correct myself,
I think youre right, the correct making external should be with the index([5]).
the array definition got lost cause i redefined it as an standard integer (without the index).
So i think the compiler thinks it is an standard variable and therefore the type failure error.
But in correct defining
Code:
extern int tst_user[5];
there is the problem with the unresolved external, which i should focus on.
error LNK2001: unresolved external symbol "int * tst_user" (?tst_user@@3PAHA)
This says nothing to me and English isn't my mother tongue and googeling the prob also doesn't help.
Could anyone please explain me the error above or give me a hint
what im doing wrong?
Thx for reading/helping
kox