?? getchar.h
字號(hào):
#include "string.h"
#include "iostream.h"
#include "fstream.h"
const MAX=20; //變量名允許的最長(zhǎng)長(zhǎng)度20
struct word //單詞結(jié)構(gòu)體
{
char *ch; //存儲(chǔ)單詞
char chname[10]; //存放單詞名
int line; //指明單詞所在行數(shù)
int type; //指明單詞的類型,保留字=0,變量=1,常數(shù)=2,還是特殊符號(hào)=3,錯(cuò)誤符號(hào)=4
} w={NULL,"\0",1,-1};
int Ischar(char c)
{
return ((c>=0x41&&c<=0x5A||c>=0x61&&c<=0x7A));
}
int Isdigit(char c)
{
return((c>=0x30&&c<=0x39));
}
void getword(word& w,ifstream myfile)
{
w.ch=new char[MAX];
for(int i=0;i<MAX;i++) w.ch[i]='\0';
char temp; //存放臨時(shí)掃描字符
myfile.get(temp);
while((temp==0x20||temp==0x0d||temp==0xA||temp==0x9)&&(!myfile.eof()))
{
if(temp==0xA) w.line++;
myfile.get(temp);
}
int j=0,len=MAX;
w.ch[j++]=temp;
if(Ischar(temp)||Isdigit(temp)) //判定是不是數(shù)字或字母
{
myfile.get(temp);
while(Ischar(temp)||Isdigit(temp))
{
if(j<MAX) //防止字符串過長(zhǎng)
{
w.ch[j++]=temp;
}
myfile.get(temp);
}
myfile.seekg(-1,ios::cur);
return;
}
if(temp=='+') //判定是不是++,+=
{
myfile.get(temp);
if(temp=='+'||temp=='=')
{
w.ch[j++]=temp;
return;
}
myfile.seekg(-1,ios::cur);
return;
}
if(temp=='-') //判定是不是--,-=
{
myfile.get(temp);
if(temp=='-'||temp=='=')
{
w.ch[j++]=temp;
return;
}
myfile.seekg(-1,ios::cur);
return;
}
if(temp=='%') //判定是不是%d
{
myfile.get(temp);
if(temp==0x64)
{
w.ch[j++]=temp;
return;
}
myfile.seekg(-1,ios::cur);
return;
}
if(temp=='/') //判定是不是//,/=,/*
{
myfile.get(temp);
if(temp=='/'||temp=='='||temp=='*')
{
w.ch[j++]=temp;
return;
}
myfile.seekg(-1,ios::cur);
return;
}
if(temp=='*') //判定是不是*=,*/
{
myfile.get(temp);
if(temp=='='||temp=='/')
{
w.ch[j++]=temp;
return;
}
myfile.seekg(-1,ios::cur);
return;
}
if(temp=='&') //判定是不是&&
{
myfile.get(temp);
if(temp=='&')
{
w.ch[j++]=temp;
return;
}
myfile.seekg(-1,ios::cur);
return;
}
if(temp=='|') //判定是不是||
{
myfile.get(temp);
if(temp=='|')
{
w.ch[j++]=temp;
return;
}
myfile.seekg(-1,ios::cur);
return;
}
if(temp=='>'||temp=='='||temp=='<'||temp=='!') //判定是不是>=,<=,!=,==
{
myfile.get(temp);
if(temp=='=')
{
w.ch[j++]=temp;
return;
}
myfile.seekg(-1,ios::cur);
return;
}
return;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -