Hey, I am learning about pointers in C and to further understand I wrote my own test code. What I am trying to do is have the console ask for a letter and then pass that argument to a function that evaluates it using a switch. When it finds the matching case an integer value is assigned to the local variable 'CritNum'. This value is then pointed back to Main to the integer variable named 'cNumber' (I hope I did not screw up my explanation terminology to much, i am learning).
Anyway, I was surprised after writing it I got no errors on my first try!!! But that joy was short lived since the program stalls after asking the first question? I am thinking the code fails in my Function but I can't see where after looking at it for an hour. If it gave me errors I could try to fix it but nothing. Any help would be appreciated.
Anyway, I was surprised after writing it I got no errors on my first try!!! But that joy was short lived since the program stalls after asking the first question? I am thinking the code fails in my Function but I can't see where after looking at it for an hour. If it gave me errors I could try to fix it but nothing. Any help would be appreciated.
Code:
#include <stdio.h>
void crit(char crit, int *cNumberPTR);
int main (int argc, const char * argv[]) {
char letter;
int cNumber;
printf("Enter a letter from A-I:");
scanf("%c", letter);
crit(letter, &cNumber);
printf("The letter %c is the number is %d", letter,cNumber);
return 0;
}
void crit(char crit, int *cNumberPTR) {
int CritNum;
switch (crit) {
case 'a':
CritNum = 10;
case 'A':
CritNum = 10;
break;
case 'b':
CritNum = 20;
case 'B':
CritNum = 20;
break;
case 'c':
CritNum = 30;
break;
case 'C':
CritNum = 30;
case 'd':
CritNum = 50;
case 'D':
CritNum = 50;
break;
case 'e':
CritNum = 70;
case 'E':
CritNum = 70;
break;
case 'f':
CritNum = 80;
case 'F':
CritNum = 80;
break;
case 'g':
CritNum = 90;
case 'G':
CritNum = 90;
break;
case 'h':
CritNum = 100;
case 'H':
CritNum = 100;
break;
case 'i':
CritNum = 120;
case 'I':
CritNum = 120;
break;
default:
CritNum = 0;
break;
}
*cNumberPTR = CritNum;
}