I am very very blurry about when to use pointers or not.
I am writing a function (given below), and trying to pass in two variables, statenumber and state. I have them being passed in as chars, and not char *s. I get error messages both ways. I dont know if I need to change them to pointers or not.
I have statenumber set as a char, because my professors specified that it needed to be "an 8 bit integer", and said I should use char. I do not understand why it need to be a char. I think that integers are saved as 4 bit numbers, or something like that. Can anyone explain why I would need it to be a char to be 8 bits? Also, is it possible at all to save a number into char??
Function:
void writestate(char statenumber, char state){
switch (statenumber) {
case 0: state = "Alabama";
case 1: state = "Alaska";
case 2: state = "Arizona";
case 3: state = "Arkansas";
case 4: state = "California";
case 5: state = "Colorado";
case 6: state = "Connecticut";
case 7: state = "Delaware";
case 8: state = "Florida";
case 9: state = "Georgia";
case 10: state = "Hawaii";
case 11: state = "Idaho";
case 12: state = "Illinois";
case 13: state = "Indiana";
case 14: state = "Iowa";
case 15: state = "Kansas";
case 16: state = "Kentucky";
case 17: state = "Louisiana";
case 18: state = "Maine";
case 19: state = "Maryland";
case 20: state = "Massachusetts";
case 21: state = "Michigan";
case 22: state = "Minnesota";
case 23: state = "Mississippi";
case 24: state = "Missouri";
case 25: state = "Montana";
case 26: state = "Nebraska";
case 27: state = "Nevada";
case 28: state = "New Hampshire";
case 29: state = "New Jersey";
case 30: state = "New Mexico";
case 31: state = "New York";
case 32: state = "North Carolina";
case 33: state = "North Dakota";
case 34: state = "Ohio";
case 35: state = "Oklahoma";
case 36: state = "Oregon";
case 37: state = "Pennsylvania";
case 38: state = "Rhode Island";
case 39: state = "South Carolina";
case 40: state = "South Dakota";
case 41: state = "Tennessee";
case 42: state = "Texas";
case 43: state = "Utah";
case 44: state = "Vermont";
case 45: state = "Virginia";
case 46: state = "Washington";
case 47: state = "West Virginia";
case 48: state = "Wisconsin";
case 49: state = "Wyoming";
}
}
This is where I declare my variables:
int main(){
char name[25] = "unknown", rating[25] = "unknown", state[25] = "unknown", statenumber[2];
int lobbyists=0, prevemploys=0, number=0;
double networth=0, tarp=0, contributions=0;
This is where I ask the user for statename:
case 2:
printstates();
scanf("%s",statenumber);
writestate(statenumber,state);
printf("State: %s\n\nEnter 9 to display options.\n\n",state);
break;