October 22, 2024
Chicago 12, Melborne City, USA
C#

The scanf function uses '%c' to accept input, but can perform string input


How to understand the running process of the following code.

void scan(void){
    char item;
    scanf("%c",&item);
    if(item == '#'){
        printf("\n");
        return;
    }
    printf("%c",item);
    scan();
}

Why can I input strings into the console, and scanf will not be executed again in the recursion, but each character will be read automatically instead?



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video