简体   繁体   中英

How to enter a string n number of times in C using scanf()

I'm trying to enter no of test cases (t) and the for n number of times enter a string and process it. Here's the code I tried:

    char str[10000];
    int size,flag,i,t;
    scanf("%d",&t);
    while(t--){
        gets(str);
        flag=1;
        size=0;
        while(str[size]!='\0')  size++;
        if(size<2)  flag=0;
        for(i=0;i<size/2;i++)
            if(abs(str[i+1]-str[i])!=abs(str[size-i-1]-str[size-i-2]))  flag=0;
        if(flag)    printf("Funny\n");
        else        printf("Not Funny\n");
    }

Also in place of using gets, I also tried:

scanf("%[^\t\n]s",str);

But nothing seems to work

Actually, I got it.

    int t;
    char str[100];
    scanf("%d",&t);
    while(t--)
        scanf("%s",str);

This works just fine.

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