I have a variable where the user inputs one number. That variable is of type int because that's the return value of fgetc(stdin) and getchar(). In this case, I'm using fgetc(stdin). After the user inputs the number, I would like to convert it to an integer with strtol(), however, I get a warning about an incompatible integer to pointer conversion because of strtol()'s first argument being a const char *. Here is the code:
int option;
char *endptr;
int8_t choice;
printf("=========================================Login or Create Account=========================================\n\n");
while(1) {
printf("Welcome to the Bank management program! Would you like to 1. Create Account or 2. Login?\n>>> ");
fflush(stdout);
option = fgetc(stdin);
choice = strtol(option, &endptr, 10);
Does anyone know how to get around this?
strtolis used to convert a "string" intolong, not a single char. You just needchoice = option - '0'to get the value. But you don't actually need to convert because you can directly switch on the char valueIf you really want to call
strtolthen you must make a string