检查参数名是否合法(C语言)
本文最后更新于35 天前,其中的信息可能已经过时,如有错误请发送邮件到suzhech@gmail.com
#include<stdio.h>
#include<string.h>
#include<ctype.h>
const char keyword[32][10] =
{
	"int","float","double","char","short","long","signed","unsigned",
	"void","auto","register","static","extern","typedef","if","else",
	"switch","case","default","for","while","do","break","continue",
	"goto","return","const","union","struct","enum","volatile","sizeof"
};
int main()
{
	char s[53];
	while (gets(s) != NULL)
	{
		int jud = 1;
		for (int i = 0; i < 32; i++)
		{
			if (!strcmp(s, keyword[i]))
			{
				jud = 0;
			}
		}
		int len = strlen(s);
		if (s[0]>='0'&&s[0]<='9')
			{
				jud = 0;
			}
		for (int i = 0; i < len && jud == 1; i++)
		{
			 
			if (!((s[i] >= '0' && s[i] <= '9') || (s[i] >= 'a' && s[i] <= 'z') || (s[i] >= 'A' && s[i] <= 'Z') ||s[i] == '_'))
			{
				jud = 0;
			}
		}
		if (jud == 1)
		{
			printf("Yes\n");
		}
		else
		{
			printf("No\n");
		}
	}
	
	return 0;
}

注意:因为使用了gets函数,所以很多情况下可能无法运行

检查参数名是否合法(C语言) by 如中
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇