I’m trying to copy PIN (there is data inside PIN) to temp. (Assuming PIN is always smaller than temp)
const char * PIN;
....
char [10] temp ="";
int i = 0;
while (*(PIN+i)) {
temp[i] = (PIN+i)*;
i++;
}
Also would it be okay if I treated temp like a pointer as such?
long int res = strtol (&temp, NULL, 10);
A few things,
temp =”\0″
Will actually put two \0 in the string, the one you wrote, and one implied by the quotation.
PIN+i needs to be dereferenced (with a *) or it will go on and on unless you can guarantee a null pointer at the end of the address space.
Then to copy the characters rather than the pointers the assignment statement should also be dereferenced.
Also why wouldn’t you just use strcpy? or strncpy?