字符命名规范化C语言的问题

[ c ]字符命名规范化
题目内容
编写程序删除 s 数组中不符合 C 语言标识符命名规则的字符
串,并输出剩余的字符串。(标识符必须以字母 a ~ Z 、
A ~ Z 或下划线开头,后面可跟任意个(可为0)字符,这些字符可以是字母、下划线和数字,其他字符不允许出现在标
识符中。)
输入
输入5个字符串
输出
输入5个字符串
输入样例
a81a12 aaa $ ss 1sSs
输出样例
a12


#include <stdio.h>
//判断函数
int isValid(char *p)
{
    //数字开头就不符合,直接返回0
    if(*p <= '9' && *p >= '0') 
    {
        return 0;
    }
 
    while(*p)
    {
        //中间的字符只能是这些
        if((*p >='A'&&*p<='Z')||(*p >='a'&&*p<='z')||(*p >='0'&&*p<='9')||*p=='_')
            {
                p++;
            }
        else 
        {
        //不符合就返回0
        return 0;
        }
    }
    //循环完就符合,返回1
    return 1;
}
int main ()
{
    
    char arr[5][100];
    int j,i;
    
    scanf("%s %s %s %s %s",arr[0],arr[1],arr[2],arr[3],arr[4]);
    for(i = 0; i < 5; i ++)
    {
        if(isValid(arr[i]))
        { 
            printf("%s ", arr[i]);
        }
        else
        {
            continue;
        }
    }
    return 0;
}
 
#include<stdio.h>
#include <string.h>

int func(char *s)
{
    if((s[0] >= 'a' && s[0] <= 'z') || (s[0] >='A' && s[0] <='Z') || (s[0] == '_'))
    {
        int i=1;
        while(s[i] != 0)
        {
            if((s[i] >= 'a' && s[i] <= 'z') || (s[i] >='A' && s[i] <='Z') || (s[i] == '_') || (s[i] >='0' && s[i] <='9'))
            {
                i++;
                continue;
            }
            else
                break;
        }
        if(s[i] == 0)
            return 1;
    }
    return 0;
}

int main()
{
    for(int i=0;i<5;i++)
    {
        char s[1000];
        scanf("%s",s);
        if(func(s) == 1)
            printf("%s ",s);
    }
    return 0;
}

#include <stdio.h>
#include <ctype.h>
#include <string.h>

#define MAX_LEN 100

int is_valid_identifier(char *s)
{
if (!isalpha(*s) && *s != '_') {
return 0;
}

while (*++s) {
    if (!isalnum(*s) && *s != '_') {
        return 0;
    }
}

return 1;
}

int main()
{
char s[MAX_LEN];
while (scanf("%s", s) == 1) {
if (is_valid_identifier(s)) {
printf("%s\n", s);
}
}
return 0;
}
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632