⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fuyanlidechengxu.cpp

📁 很有问题的代码
💻 CPP
字号:
#include <string.h>
#include <stdio.h> 
#include <stdlib.h>
struct code_val{
       char code;
       char val[20];
       };        
       
 
   
void main()			            
       {
             char buf[5000]={'\0'};
             int i=0;
             FILE *fp,*fp2;
             struct code_val scanner(char *buf,int i);
             void pro_process(char *buf);  
             if((fp=fopen("program.txt","r"))==NULL) 
             {
                  printf("cannot open this file\n");
                  exit(0);
             }
               if((fp2=fopen("result.txt","w"))==NULL)
             {
                  printf("cannot open this file\n");
                  exit(0);
             }
             pro_process(buf);
             struct code_val t;         
             do{
                  t=scanner(buf,i);    
				  fprintf(fp2,"%c\t%s\n",t.code,t.val);  
             }while(t.code!='#'); 
             printf("End of analysis!\n"); 
             fclose(fp);   
             fclose(fp2);  
       }

    void pro_process(char *buf)   
       { int i=0;FILE *fp=fopen("program.txt","r");
	     buf[i]=fgetc(fp);
		 do 
		 {if(buf[i]=32)
		 do buf[i+1]=fgetc(fp);while(buf[i+1]=32);i++;buf[i]=fgetc(fp);
		 }
		 while(buf[i]!='#');
        }
struct code_val scanner(char *buf,int i)
        {     int k, j=0;i=0;
              char string[20];
              char ident[][20]={"break","char","main""new","return","short","struct","switch","then","void","while","\0"};
              struct code_val t;
              while(buf[i]=='/0')
              i++;
             
             if(buf[i]>='a'&&buf[i]<='z'||buf[i]>='A'&&buf[i]<='Z') 

         
           {do 
			 
			 {*(string+j)=*(buf+i);
                 i++;j++;
                   }while((buf[i]>='a'&&buf[i]<='z')||(buf[i]>='A'&&buf[i]<='Z')||buf[i]>='0'&&buf[i]<='9');
               for(k=0;strcmp(ident[k],"\0")!=0;k++)  
                  {
                     if(strcmp(string,ident[k])==0)  
                     t.code='-'; strcpy(t.val,string);
                  }
                  if(t.code!='-'){t.code='0';strcpy(t.val,string);}
               i++;
               if(buf[i]!='\0')
               printf("the program is wrong guanjian!");
               return(t);

             }
             
            else if(buf[i]>='0'&&buf[i]<='9')
             {do {*(string+j)=*(buf+i);
                       i++;j++;
                  }while(buf[i]>='0'&&buf[i]<='9');
              t.code='1'; strcpy(t.val,string);
              i++;
              if(buf[i]!='\0')
              printf("the program is wrong data!");
              return(t);          
             }
             
           else { switch(buf[i])
                   { 
                    case'=':{t.code='-'; strcpy(t.val,"=");i++;}break;
                    case'+':{t.code='-'; strcpy(t.val,"+");i++;}break;
                    case'-':{t.code='-'; strcpy(t.val,"-");i++;}break;
                    case'*':{t.code='-'; strcpy(t.val,"*");i++;}break;
                    case',':{t.code='-'; strcpy(t.val,",");i++;}break;
                    case';':{t.code='-'; strcpy(t.val,";");i++;}break;
                    case'(':{t.code='-'; strcpy(t.val,"(");i++;}break;
                    case')':{t.code='-'; strcpy(t.val,")");i++;}break;
                    case'{':{t.code='-'; strcpy(t.val,"{");i++;}break;
                    case'}':{t.code='-'; strcpy(t.val,"}");i++;}break;
                    case'<':{t.code='-'; strcpy(t.val,"<");i++;}break;
                    case'>':{t.code='-'; strcpy(t.val,"<");i++;}break;
                    case'>=':{t.code='-'; strcpy(t.val,">=");i++;}break;
                    case'<=':{t.code='-'; strcpy(t.val,"<=");i++;}break;
                    case'#':{t.code='#'; strcpy(t.val,"#");i++;}break;
                    default:printf("the program is the wrong case!\n");
                   }
                 return t; 
                }
     }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -