scanf的正则表达式

// scanf正则表达式.cpp : Defines the entry point for the console application.
//


#include "stdafx.h"
#include <stdio.h>


int main1(int argc, char* argv[])
{
char str[100]={0};
//scanf("%s",str);//空格当做结束


//scanf("%[^\n]",str);//遇到回车就结束


//scanf("%[^=]",str);//等号作为结束符


scanf("%[^,]",str);//以英文的逗号结束


printf("str=%s\n",str);
return 0;
}


//scanf("%[^a]",str); %[^a]这样的正则表达式
void main2()
{
char str[100]={0};
//scanf("%[1]",str);//只能输入进去1不然就遇到不是1就结束
//scanf("%[0-9]",str);//输入不是0-9就结束也就是只能输入数字
//scanf("%[A-Z]",str); //不是A-Z就结束
scanf("%[^A-Z]",str);//只要输入A-Z就会结束
//scanf("%[0-9a-zA-Z]",str);//只能输入字母加数字
printf("str=%s\n",str);
}
void main()
{
int QQ=0;
char password[20]={0};
scanf("%d",&QQ);
scanf("%[^ ]",password);
printf("QQ:%d\n",QQ);
printf("密码:%s\n",password);




}
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值