// 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);
}
//
#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);
}