![](https://csdnimg.cn/release/download_crawler_static/86369468/bg4.jpg)
void scanner()
{
ifstream output;
output.open("input.txt");//读取文件
char structer[11][10] = { "if", "else", "for", "return", "switch", "case", "break",
"continue", "while", "do" ,"goto"};//基本结构
char dataType[14][10] = { "int", "char", "float", "double",
"void","signed","unsigned","short","long","static","struct","union","typedef","volatile
" };//数据类型
char preDeal[2][10] = { "include", "define" };//预处理符号
char word[30] = { '\0' };
int i = 0;//扫描结果数组下标
bool k = false;//记录单词状态
int a = 0;//扫描小数时循环的控制变量
int b = 0;//扫描注释时循环的控制变量
int state = 1;//循环中case的默认取值
char ch;
ch = output.get();
characterNum++;
while (ch != '$')//未结束
{
//输入字符是分隔符
if (ch == '\n' || ch == ' ' || ch == '\0' || ch == '\t')
{
if (ch == '\n')
{
lineNum++;
}
ch = output.get();
characterNum++;
}
else if (((ch >= 'a') && (ch <= 'z')) || ((ch >= 'A') && (ch <= 'Z')))//输入为
字母
{
word[i++] = ch;
characterNum++;
ch = output.get();
while (((ch >= 'a') && (ch <= 'z')) || ((ch >= 'A') && (ch <= 'Z')) ||
((ch >= '0') && (ch <= '9')||(ch=='_')))
{
word[i++] = ch;
ch = output.get();