I'm developing a c++ code which reads a line from the console like this:
-I want to check the first character.
-If it's "a" then i'll put the integer value after the equal on a variable that is an argument of the function. I want to use this variable outside the function (not a global variable)
-If it's a "b" then it's boolean
-If it's a "c" then its a string.
Call my function (maybe something like this):
ReadConsoleLine(&a, &b, c);
The first character is an "a", therefore i'm going to change the variable "a" to 34.
I have this, code....
Will this work?
void ReadConsoleLine(int a, bool b, char *c)
char str ;
char * strtoken;
strtoken = strtok (str,"=");
while (strtoken != NULL)
strtoken = strtok (NULL, "="); //gets the text after the equal
strncpy (tp,str,1); //gets the first character
if(strcmp(tp, "a") == 0)//integer
a = atoi(strtoken);
if(strcmp(tp, "b") == 0)//BOOL
b = (strcmp(strtoken, "False");
if(strcmp(tp, "c") == 0)//String
Will this code work?
Thanks in advance