Search code examples
cprogram-entry-point

I am trying to scan a char in my main method and my program just prints and exits


I am trying to scan and my method just prints and exits. It won't scan.

int main() {
    char *one = (char*)malloc(34* sizeof(char));
    char *two = (char*)malloc(16* sizeof(char));
    char test ;
    printf("please enter a Q \n");    
    scanf("%c", test);
    printf("%c\n", test); 
    return 0;
}

Solution

  • scanf("%c", test);
    

    should be:

    scanf("%c", &test);