Hello all,
please how to convert char* to char ?
the last line of this code is error because the " var " is type of char but the " result " is char* ,
How can I take a number from the result to var so I can be use var as number like ' if ( var > 2 ) { }'
//***********************************
char result[ 10 ] , temp[ 10 ];
char var;
void setup(){
memset( result, 0, sizeof( result));
}
void loop(){
var = 123 ;
itoa( var, temp, 10);
strncpy( result, &temp[1],1);
var = result ;
//************************************
system
August 22, 2015, 11:55am
2
To convert a char pointer to a char is meaningless and pointless.
Please, please remember to use code tags when posting code.
system
August 22, 2015, 12:05pm
3
memset( result, 0, sizeof( result));
Write over all of the NULLS that the compiler put in result with more NULLS. Why?
strncpy( result, &temp[1],1);
As opposed to:
result[0] = temp[1];
? Why?
Or
var = temp[1];
? Why?
PaulS:
memset( result, 0, sizeof( result));
Write over all of the NULLS that the compiler put in result with more NULLS. Why?
strncpy( result, &temp[1],1);
As opposed to:
result[0] = temp[1];
? Why?
Or
var = temp[1];
? Why?
in my Example the result will be take one digit of the number, but if I write this code:-
var = temp[1];
the var not take one digit because var not char*
system
August 22, 2015, 3:09pm
5
the var not take one digit because var not char*
The value in temp[1] is not a pointer, either.