scanf() rush through

rdson@esp
Posts: 8
Joined: Wed Jun 15, 2022 8:41 am

scanf() rush through

Postby rdson@esp » Thu Jun 16, 2022 10:36 am

Hi there,

I thought to use the scanf() function to get the user's choice from a displayed menu over the UART0 but it doesn't stop at the scanf() function to wait for a user input... and simply rushes endlessly the while(1) loop executing the default from the switch case.

Why? I went through this interessting post http://sekrit.de/webdocs/c/beginners-gu ... scanf.html but couldn't fix my issue though...

Code: Select all


while(1){
	
	int choice = 0;
	
	... some printf() ...
	
	printf("Your choice:");
        scanf("%1d", &choice);

        switch(choice){

            case 1:						// Lists files and folders of SD card
                list_sd_data();
                printf("Hit any key to go back");
                scanf( %*d");
                break;

            default:
                printf("Yet not implemented\n");
                break;

        }
}
        
   

Who is online

Users browsing this forum: No registered users and 386 guests