キーボードで入力した英数字や演算子を表示させるプログラムなのですが、
英字を一文字ずつ出力させるのではなく全部まとめて出力したいのですがどうかけばいいかわかりません。
isalphaの部分です。
お願いします。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#define STR_LEN 256
#define BSIZE 1024
char buff[BSIZE];
char *bp;
enum tokentype{PLUS,MINUS,ASTERISK,SLASH,PERCENT,LPAREN,RPAREN,NUMB,END,IDENT};
struct{
enum tokentype type;
int val;
char str[STR_LEN];
}token;
void error(char *msg);
void scan();
void error(char *msg){
if(msg == NULL)
puts("error");
else
puts(msg);
exit(1);
}
void scan(){
token.val=0;
memset(token.str,'\0',STR_LEN);
if(isdigit(*bp)){
token.val=strtol(bp,&bp,10);
sprintf(token.str,"%d",token.val);
token.type = NUMB;
return ;
}
if(isalpha(*bp)){
token.str[0]=*bp;
token.type=IDENT;
bp++;
return ;
}
if(*bp == '+'){
token.str[0] =*bp;
token.type=PLUS;
bp++;
return ;
}
if(*bp =='-'){
token.str[0]=*bp;
token.type=MINUS;
bp++;
return;
}
if(*bp =='*'){
token.str[0]=*bp;
token.type=MINUS;
bp++;
return;
}
if(*bp =='-'){
token.str[0]=*bp;
token.type=ASTERISK;
bp++;
return;
}
if(*bp =='/'){
token.str[0]=*bp;
token.type=SLASH;
bp++;
return;
}
if(*bp =='%'){
token.str[0]=*bp;
token.type=PERCENT;
bp++;
return;
}
if(*bp =='('){
token.str[0]=*bp;
token.type=LPAREN;
bp++;
return;
}
if(*bp ==')'){
token.str[0]=*bp;
token.type=RPAREN;
bp++;
return;
}
if(*bp =='$'){
token.str[0]=*bp;
token.type=END;
bp++;
return;
}
error("unknown token\n");
}
int main(){
fgets(bp=buff,BSIZE,stdin);
while(1){
scan();
printf("TYPE:%3d",token.type);
if(token.type == NUMB)
printf("VAL:%d\n",token.val);
else
printf("STR:%s\n",token.str);
if(token.type==END)
break;
}
return 0;
}