#include<stdlib.h>
#include<stdio.h>
#include<string.h>
/*******************************************
主函数
********************************************/
main()
{
int i;
init(); /*初始化*/
i=scanner(); /*扫描源程序*/
if(i==1)
printf("The answer is in 'output.txt':");
getch();
}
/*******************************************
初始化函数
********************************************/
void init()
{
char *key[]={" ","auto","break","case","char","const","continue","default","do","double",
"else","enum","extern","float","for","goto","if","int","long","register",
"return","short","signed","sizeof","static","struct","switch","typedef",
"union","unsigned","void","volatile","while"}; /*C语言所有关键字,共32个*/
char *limit[]={" ","(",")","[","]","->",".","!","++","--","&","~",
"*","/","%","+","-","<<",">>","<","<=",">",">=","==","!=","&&","||",
"=","+=","-=","*=","/=",",",";","{","}","#","_","'"};/*共38个运算、限界符*/
FILE *fp;
int i;
char c;
fp=fopen("key.txt","w");
for(i=1;i<=32;i++)
fprintf(fp,"%s\n",key[i]);
fclose(fp);/*初始化关键字*/
fp=fopen("limit.txt","w");
for(i=1;i<=38;i++)
fprintf(fp,"%s\n",limit[i]);
c='"';
fprintf(fp,"%c\n",c);
fclose(fp); /*初始化运算、限界符表*/
fp=fopen("id.txt","w");
fclose(fp); /*初始化标识符表*/
fp=fopen("constant.txt","w");
fclose(fp); /*初始化常数表*/
fp=fopen("output.txt","w");
fclose(fp); /*初始化输出文件*/
}
/*******************************************
十进制转二进制函数
********************************************/
char * dtb(char *buf)
{
int temp[20];
char *binary;
int value=0,i=0,j;
for(i=0;buf[i]!='\0';i++)