为什么要为scanf输入放置多个句点会跳过下一个scanf函数?

问题描述 投票:0回答:1

为什么为scanf输入放置多个句点会跳过下一个scanf函数。示例输入:b. b.

int main (void) {

    char b[7] = " ";

    printf("This is: ");
    scanf(" %s", b);

    printf("This is 2nd: ");
    scanf(" %s", b);

    printf("This is 3rd: ");
    scanf(" %s", b);

    printf("\nThis is 4rth: %s\n", b);
    printf("This is 5th: %s", b);

    return 0;
}

//输出

This is: b. b.

This is 2nd: This is 3rd:
c scanf
1个回答
0
投票

不是句号的问题,跳过下一个scanf语句是因为您的输入包含空格。

请检查链接说明-Taking String input with space in C

© www.soinside.com 2019 - 2024. All rights reserved.