首页 > 代码库 > 字符串
字符串
Queue DeleteQ(Queue Q)//出队列
{
int i=t++;
QueueNode *p;
char y=NULL;
if(Q.front==Q.rear)
{
printf("队列为,无法出队列!");//判断队列是否为空
return(Q);
}
p=Q.front->next;
y=Q.front->next->data;//将队列中的元素赋值给y
Q.front->next=p->next;
if(p==Q.rear)
Q.rear=Q.front;
if((y>=‘A‘&&y<=‘Z‘)||(y>=‘a‘&&y<=‘z‘))//利用ASCII判断y是否是属于字母,并存储在数组str中
str[i]=y;
else
{
if(str[0]!=NULL)//如果数组str非空,则输出
Print(str);
t=0;
if(y==‘+‘||y==‘-‘||y==‘*‘||y==‘/‘||y==‘:‘||y==‘<‘||y==‘>‘)//判断字符是否是运算符
{
if(p->next->data=http://www.mamicode.com/=‘=‘)//判断运算是否是由两个字符组成
{
printf("(运算符,%c%c)\n",y,p->next->data);
Q.front->next=p->next->next;
free(p->next);
}
else
printf("(运算符,%c)\n",y);
}
else if(y==‘=‘)//判断字符是否是运算符
printf("(运算符,%c)\n",y);
else if(y>=48&&y<=57)//判断字符是否为数字
{
st[t1]=y;//将字符数字赋值给数组st
t1++;
if(p->next->data<48||p->next->data>57)//判断队列中下一个字符是否为数字,如果是非字符数字,则输出数组st
if(st[0]!=‘\o‘)
printf("(常数,%s)\n",st);
}
else if(y==33||y==34||(y>=39&&y<=41)||y==44||y==46||y==58||y==59||(y>=91&&y<=96)||(y>=123&&y<=125))//判断是否为界符
printf("(界符,%c)\n",y);
else if(y==‘ ‘)
printf("(空格符,%c)\n",y);//判断空格符
else
printf("(特殊符号,%c)\n",y);//其他的当作特殊符号处理
}
free(p);
return Q;
}
int main()
{
char x,y;
Queue p,q;
p=InitQueue();
printf("请输入你想输入字符串:\n");
while(scanf("%c",&x)==1&&x!=‘\n‘)//大神的方法,牛
p=InserQ(p,x);
q=p;
while(p.front!=p.rear)
p=DeleteQ(p);
if(str[0]!=‘\o‘)//判断数组str是否为空
Print(str);
}
void Print(char str[])//调用函数来判断关键字与标识符
{
int i=0;
if(strcmp(str,"break")==0||strcmp(str,"case")==0||strcmp(str,"char")==0||strcmp(str,"const")==0||strcmp(str,"continue")==0||strcmp(str,"default")==0||strcmp(str,"do")==0||strcmp(str,"double")==0||strcmp(str,"else")==0||strcmp(str,"enum")==0||strcmp(str,"extern")==0||strcmp(str,"float")==0||strcmp(str,"for")==0||strcmp(str,"goto")==0||strcmp(str,"if")==0||strcmp(str,"int")==0||strcmp(str,"long")==0||strcmp(str,"register")==0||strcmp(str,"return")==0||strcmp(str,"short")==0||strcmp(str,"signed")==0||strcmp(str,"sizeof")==0||strcmp(str,"static")==0||strcmp(str,"struct")==0||strcmp(str,"switch")==0||strcmp(str,"typedef")==0||strcmp(str,"unsigned")==0||strcmp(str,"union")==0||strcmp(str,"void")==0||strcmp(str,"volatile")==0||strcmp(str,"while")==0||strcmp(str,"auto")==0)
printf("(关键字,%s)\n",str);
else
{
if(str[0]==‘\0‘)
return;
printf("(标识符,%s)\n",str);
}
memset(str,0,N);//清空数组str里的所有元素
}
字符串