I am trying to cast a string to an int in C and I found really nice examples in the internet, like on: Converting string to integer C
OR:
char *A = "123";
int = A - '0';
But whatever solution I use, when I do it char to char in my program I get that warning.
So I first have a char array I split into separate parts. It looks like "1 2 3 4", and then I want to cast them to int:
char *a = "1 2 3 4";
char deli[] = " ";
char *ptr;
ptr = strtok(a, deli);
while (ptr != NULL) {
int num = ptr - '0'; // or any other method which is casting the part now to an int causes the warning
ptr = strtok(NULL, deli);
}
Does someone see what am I doing wrong here?