Hello again. I tried to figure this out for the last few hours before I came here. I like trying to solve the problems myself if I can. it's not returning the *valuePtr from the function to change the int value.
I stripped this out of my larger program to find out what was going on in a separate xcode window. The Function Prototype has 2 parameters a pointer and a char. It passes the Char 'J' and the &value to a Switch that finds the case for 'J' and assigns an int value to i. i is then passes on to *value but it never make is back to int value in main(), it's still assigned to zero.
Thanks.
-Lars
I stripped this out of my larger program to find out what was going on in a separate xcode window. The Function Prototype has 2 parameters a pointer and a char. It passes the Char 'J' and the &value to a Switch that finds the case for 'J' and assigns an int value to i. i is then passes on to *value but it never make is back to int value in main(), it's still assigned to zero.
Code:
#include <stdio.h>
void charToInt(int *valuePtr, char card);
int main (int argc, const char * argv[]) {
int value;
char mixDeck[2];
mixDeck[0] = 'J';
mixDeck[1] = '\0';
value = 0;
charToInt(&value, mixDeck[0]);
printf("The value is %d\n", value);
printf("The value is %s", mixDeck);
return 0;
}
void charToInt(int *valuePtr, char card)
{
int i;
switch (card) {
case '2':
i = 2;
break;
case '3':
i = 3;
break;
case '4':
i = 4;
break;
case '5':
i = 5;
break;
case '6':
i = 6;
break;
case '7':
i = 7;
break;
case '8':
i = 8;
break;
case '9':
i = 9;
break;
case 'T':
i = 10;
break;
case 'J':
i = 10;
break;
case 'Q':
i = 10;
break;
case 'K':
i = 10;
break;
case 'A':
i = 11;
break;
default:
i = 9999;
break;
*valuePtr = i;
}
}
Thanks.
-Lars