还剩12页未读,继续阅读
本资源只提供10页预览,全部文档请下载后查看!喜欢就下载吧,查找使用更方便
文本内容:
;words[j]=\0flag=;}415else flag=416;;break}case/{if ch==7;words[j++]=chwords[j]=5\09;;ch=program[i++]ifch==-9{words[j++]=ch;;words[j]=\0flag=417;else flag=418;break;;case{words[j]=ch;words[j+1]=\0;flag=501;;break}{case words[j];=ch;words[j+l]=\0flag=;502break;case{words[j]=ch;words[j+1]=\T;flag=503;break;case*[1:{words[j]=ch;words[j+l]=,\0,;flag=504;break;case]{words[j]=ch;,;words[j+1]=T flag;;=505break case*{*{words[j]=;,;ch words[j+1]=\0;;flag=506breakcase}:{words[j]=ch;words[j+l]=,\0,;flag=507;;breakcase:{words[j]=ch;,;words[j+1]=\X flag=508;;}breakcase””:{words[j]=ch;,;;words[j+1]=\0flag=509;break,%,;case{if ch==%words[j++]=chwords[j]=*\09;;ch=program[i++]if ch==words[j++]=ch;words[j]=*\05;flag=510;else flag=511;}break;case:{words[j]=ch;,;words[j+1]=\y flag=512;;break}case#{]=;words ch;words[j+l]=\0;flag=513break;case@:{;words[j]=flag=0break;default{一;;flag=1breakreturn flag;main{;i=0printf^please inputa programend with@;doch=getchar;program[i++]=ch;;}while ch!=@i=0;do{;flag=Scanprogramif flag==200{,printf%2d,%4d”flag,number;else ifflag==-1printfH%d,error%flag;,else printff%2d,%4s”flag,words;}while flag!=0;;}system pause”修改后源代码#includeHstdioh#include”stdlib h・#includestring h”intij,k,flag,number status;5;/*status whichis useto judgethe stringis keywordsor not!7char ch={};char words
[10];char program
[500]int Scancharprogram[]『,char*keywords
[15]=voidJmain“if,,,“then break”JintJcharJfloatTinclude”JfdrJwhile“printFJscanf,define”,“double};number=0;status=0;;j=0;ch=program[i++]/*To handlethe lettlespace andstab*//*handle letters*/〈=N ifch=2chwhile ch=ach=z;words[j++]=chch=program[i++];words[j++]=\0;;fork=0;k15k++if strempwords,keywords[k]==0switch kcase0{;flag=1;status=1break;case1{;flag=2status=1;;break}case2{flag=3;status=1;break;case3{;flag=4status=1;break;}case4{flag=5;status=1;;break}case5:{;flag=6status=1;break;}case6:{flag=7;status=1;;break;;}case7:{flag=8status=1;breakcase8:{flag=9;status=1;break;;}case9:{flag=10;status=1;break;case10:{flag=11status=1;break;;;case11:{flag=12status=1break;};;case12{flag=13status=1break;};;case13{flag=14status=1;break case14{flag=15;status=1;break;}if status==0;flag=100/*handle digits*/〉=〈=else if ch ch9number=0;〉〈=while ch=V ch9number=number*10+ch-O;;ch=program[i++]flag=200;■I——;}{fopereation andedge handle*/else switchch case{if ch===words[j++]=ch;,wordsfj]=\T;ch=program[i++];一if ch——;;words[j++]=ch words[j]=\0;flag=401;}else flag=402break;〉,{case,>,if ch==words[j++]=ch;;words[j]=\0;ch=program[i++]if ch==-0;words[j++]=ch words[j]=\0;flag=403;else flag=404;break;}〈{,〈,;;;case*ifch==words[j++]=ch words[j]=0ch=program[i++]if ch==;;words[j++]=ch words[j]=\0;flag=405else flag=406;break;case!{「;;if ch==words[j++]=ch words[j]=\0ch=program[i++];if ch==;;;words[j++]=ch words[j]=*\0*flag=407;}else flag=408;}breakcase+:{;;if ch==+words[j++]=ch words[j]=\0’;ch=program[i++]if ch===words[j++]=ch;;words[j]=\0flag=409;else if ch=+words[j++]=ch;words[j]=\0’;flag=410;else flag=411;;breakcase-{if ch==-;words[j++]=chwords[j]=ch=program[i++];if ch==words[j++]=ch;;words[j]=\0flag=;}412else ifch==——words|j++]=ch;;words[j]=\T;flag=413else flag=414;break;}case*:{if ch==*words[j++]=ch;words[j]=\0;ch=program[i++];if ch==,=,;words[j++]=ch,;words[j]=\CT flag=415;;else flag=416;break}case7:{if ch==/words[j++]=ch;words[j]=\0;ch=;program[i++]if ch==words[j++]=ch;;words[j]=\0;flag=417}else;i—flag=418;case7{;flag=8;status=1;break}case8:{flag=9;status=1;;breakcase9:{;flag=10;status=1break;}case10{flag=11;status=1;;breakcase11:{;flag=12status=1;break;case12:{;flag=13status=1;break;}if status==0{;flag=100/*handle digits*/〈=else if ch=0ch9number=0;〉廿,〈=while ch0ch9tnumber=number*10+ch—0ch=program[i++];}flag=200;;i-fopereation andedge handle*/else switchch case{,if ch===words[j++]=ch;;;words[j]=\0ch=program[i++]if ch==-9words[j++]=ch;words[j]=*\05;;flag=401else flag=402;break;〉{case if ch==words[j++]=ch;words[j]=\0’;;ch=program[i++]if ch==={words[j++]=ch;;words[j]=O;flag=403};}else flag=404;break case5〈:{ifch==Y words[j++]=ch;words[j];;=\0ch=program[i++]if ch==words[j++]=ch;words[j]=AO9;flag=405;else i—;;flag=406break;case’!’{if ch==’!words[j++]=ch;words;[j]=\0ch=program[i++]if ch==-9{;;words[j++]=ch words[j]=\0flag=407;else{;i--;flag=408;breakcase+:{中;,if ch==words[j++]=ch words[j]=;\0;ch=program[i++]if ch===words[j++]=ch;,,;words[j]=\0;flag=409else ifch=+words[j++]=ch;words[j]=\0;flag=410;else;flag=411break;;case-{ifch==words[j++]=ch words[j]=*\05;,,ch=program[i++];ifch===words|j++]=ch;words[j]=\0;flag=412;,一,else iRch==;words[j++]=ch;words[j]=\0flag=413;};else flag=414;break case***{ifch==*words[j++]=ch;;words[j]=\0ch=program[i++];ifch===words[j++]=ch;。