判断一个字符串是否合法,答案全是no该怎么改

问题描述
输入一个字符串,判断其是否是C的合法标识符。合法字符定义如下:

1)字母、数字组成的序列,但其第一个字符必须为字母。

2)下划线“_”被看做字母。

预置代码
输入
输入数据包含多个测试实例,数据的第一行是一个整数n,表示测试实例的个数,然后是n行输入数据,每行是一个长度不超过100的字符串。

输出
对于每组输入数据,输出一行。如果输入数据是C的合法标识符,则输出"yes",否则,输出“no”。

输入样列
3
12ajf
fi8x_a
ff ai_2

输出样例
no
yes
no


#include<stdio.h>
#include<ctype.h>
int main()
{
    int i,t;
    char str[101];
    scanf("%d",&t);
    getchar();
    while(t--){
        gets(str);
        if(!str[0]=='_'||(str[0]>='a'&&str[0]<='z')||(str[0]>='A'&&str[0]<='Z'))
        {
            printf("no\n");
            continue;
        }
        else{
            for(i=1;str[i]!='\0';i++){
                if(!str[i]=='_'||(str[i]>='a'&&str[i]<='z')||(str[i]>='A'&&str[i]<='Z')||(str[i]>='0'&&str[i]<='9'))
                {
                    printf("no\n");
                    break;
                }
            }
        if(str[i]=='\0') printf("yes\n");
        }
    }
    return 0;
}