简体   繁体   中英

scanf function skips values in while loop for scanning character value

#include<stdio.h>

int main()
{
    int i,t;
    char c;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%s",&c);
        printf("%c",c);
    }
    return 0;
}

inside the while loop why it skips some of values. but it works okay with integer values

%s用于扫描字符串(不是char的字符串),更改为%c

this could be a solution. use:

scanf(" %c",&c);

instead of:

scanf("%c",&c);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM