Char array to Const char *?

Im sure this has been asked many times but i havnt managed to find a solution by searching?

I have my buffer as a char array, and i want to use the strtok_r function to parse it, but it needs to be const char? (char*)

How do i cast/convert it?

Thanks
Andy

Sorry, it appears i was reading the error incorrect, the error was actually referring to param 3 of strtok_r, i had a char * var that it uses, and to get it to work i had to put a & infront of it (found within code off the internet), what does the & do when put infront of vars then?

Thanks
Andy

what does the & do when put infront of vars then?

It causes the address of the variable to be evaluated, instead of the variable itself, so gives you a pointer to the variable

ahh i see, thanks.

Andy

and i want to use the strtok_r function to parse it

No, you don't. The strtok_r() function is the thread-safe version of strtok(). On a single threaded platform, why do you need the complexity and overhead of a thread-safe function? The strtok() function is far easier to use, too.

Ok, sounds better although im not really getting the result i want. :confused:

i basically have a char array 'configBuff' and it set to "0,1024,-20,20,"

I then have these:

EEPROM_writeAnything(BPIFRM, strtok(configBuff,","));
EEPROM_writeAnything(BPITO, strtok(NULL,","));
EEPROM_writeAnything(BPFRM, strtok(NULL,","));
EEPROM_writeAnything(BPTO, strtok(NULL,","));

But when i read them back there not the values i want deliting, infact it appears as though what should be -20 & 20 is 739 & 743???

will carry on experimenting...

Thanks
Andy

The strtok() function returns a pointer to a string. It is that string that you are storing in the EEPROM, not the integer that the string represents. You need to confirm that strtok() returned a valid pointer, and, if so, call atoi() with that string, and store the output in EEPROM. If, you are trying to read that string from EEPROM as an int, that is.

Why do you combine strings with EEPROM_writeAnything() ?
Why do you waste valuable EEPROM space with strings ?

I guess you want to

struct { int ifrom; int ito, int from; int to; } config;

const char delim[] = ",";
config.ifrom = atoi ( strtok( buffer, delim));
config.ito = atoi ( strtok(NULL, delim));
....

EEPROM_writeAnything(0, config);