/******************************************************************* これは AIPS対人会話システムの実現のための     単純機能の C 言語 Program の試作品です。 まず、INPUT DATA BASE としてAIPS001DB.txtが必要です。 そして、Link 情報 としてAIPS001LK.txtが必要です。 ********************************************************************    int main(void) の機能の説明です。 ********************************************************************* (1) Type, Hello, how are you ? (2) Set { BYE=0; norecog=0; } (3) readline(); read the command line. (4) If the command is 'BYE !' { BYE=1 and the program ends.} (5) If the command is 'if i say,' { NewCMD();BYE=2; goto (2);} (6) If BYE =0 { check the command line...check(); } (7) If BYE=3, goto (2); (8) If recog is 0, { set norecog=norecog+1;and write I don't understand... } (9) If norecog < 2, goto step (2). (10) If norecog = 2 , program ends with a good-bye message. BYE=1 if the command line = BYE ! BYE=2 if the command line = if i say, BYE=3 if the command line = C-program 000p *********************************************************************        関数 int NewCMD(void) の定義の中で出力 data が                   data base file名 ( AIPS001DB.txt )            が読み書きされます。         int NewCMD(void) {           FILE *fpA;FILE *fpB;           fpA=fopen("AIPS001DB.txt","r");           fpB=fopen("AIPS001DB.txt","w");                。。。。。。 とあります。    ********************************************************************* *********************************************************************      関数 int check(void) の定義の中で出力 data が                   data base file名 ( AIPS001DB.txt )            に書き込まれます   int check(void){ FILE *fpA; fpA=fopen("AIPS001DB.txt","r");           。。。。。。 とあります。 ********************************************************************* *********************************************************************      関数 int CheckOya(void) の定義の中で出力 data が                   data base file名 ( AIPS001LK.txt )            に書き込まれます             int CheckOya(void) { int ikid,jkid,lenOYA,iY;        FILE *fpA;fpA=fopen("AIPS001LK.txt","r");                        。。。。。。 とあります。 ********************************************************************* ******************* DATA BASE の構造例******************* 2 <-- Number of OYA MyGirl <-- First OYA NAME 1 <-- Number of KID of First OYA YOSHIKO <-- First KID NAME of First OYA beautiful <-- Second OYA NAME 1 <-- Number of KID of Second OYA MyGirl <-- First KID NAME ofSecond OYA ******** 実際のDATA BASE (AIPSTalkDB.txt) の構造例 ************* 21 001 how are you you I I am fine. 002 who are you I am your computer. 003 what are you I am a computer. 004 can you sing No, I cannot sing. 005 who is your teacher My teacher is  Prof.Yoshiaki Hagiwara. 006 what is your teacher My teacher is a computer scientist. 007 where do you live I live in Professor Hagiwara's Lab. 008 robot password sojorobotslide2013 is the password.... 009 number password sojonumberslide2013 is the password... 010 dct password AIPSdctnumberslide2013 is the password.... 011 what can you do I can computer any task you have taught me. 012p 2jishiki **** 2次方程式を解きます。*** 013p 2to10 *** 2進法から10進法へ変換します。*** 014p 10to2 ***10進法から2進法へ変換します。*** 015 what is your name ? My name is Yoshi. 016 How are you ? I am fine, thank you. And you ? 017 What are you ? I am an AIPS computer. 018 Where are you ? I am in Atsugi-city. 019 I am fine. Good. 020p dentaku *** 電卓です。演算子=( + - * / s r e l n 1 2 )*** 021p PtoQ **** P 進法数を Q進法数に変換します。**** *********************************************************************/ #include #include #include #define K 100 char cc,c1,c2,c3,C[K],B[K],A1[10],A2[10],A3[10],A4[10],A5[10],SP[3], A6[10],A7[10],A8[10],A9[10],AA[10],B1[10],B2[10],B3[10], B4[10],B5[10],B6[10],B7[10],B8[10],B9[10],OYA[10],KID[10], S1[10],S2[10],S3[10],S4[10],S5[10],S6[10],SOYA[10],SKID[10],SMAG[10]; int lenA,lenA1,lenA2,lenA3,lenA4,lenA5,lenA6,lenA7,lenA8,lenA9,iA,jA,PP,iSP, line,lenB,lenC,NSS,ISS,iC,jB,i,j,k,kB,recog,norecog,recogA; int test=1,BYE,NoCheckA4,NoCheckA2,iset,nset,FINISH,NKID,GEN, OYAflag,KIDflag,MAGflag,Gset,Level; int dig;char CH; /************ Special Subroutine Program ************************** int SP021(void) PtoQ int SP020(void) DENTAKU int SP014(void) 10to2 int SP013(void) 2to10 int SP012(void) 2jishiki ***********************************************************************/ /*********************************************************************** PtoQ int SP021(void) ************************************************************************* char P,Q,p[500],d[500],b[500],q[500]; int pN,dN,bN,qN; ************************************************************************* Give the number system P and Q; P and Q can be any number from 2 to 31:  2=00010          3=00011 4=00100 5=00101 6=00110 7=00111 8=01000 9=01001 A=10=01010 B=11=01011 C=12=01100 D=13=01101 E=14=01110 F=15=01111 G=16=10000 H=17=10001 I=18=10010 J=19=10011 K=20=10100 L=21=10101 M=22=10110 N=23=10111 O=24=11000 P=25=11001 Q=26=11010 R=27=11011 S=28=11100 T=29=11101 U=30=11110 V=31=11111 ******************************************************* Give p[] = P-system number of pN digits: p[pN-1],p[pN-2], ----,p[2],p[1],p[0] Obtain the binary system number of bN digits : b[bN-1],b[bN-2], ---,b[2],b[1],b[0] ; Obtain the decimal system number of dN digits : d[dN-1],d[dN-2], ---,d[2],d[1],d[0] ; and also the Q-system number of qN digits ; q[qN-1],q[qN-2], ---,q[2],q[1],q[0] ; *******************************************************************/ int digit( void ) { int i=777;char c; c=CH; if ( c=='0' ) i=0;if ( c=='1' ) i=1;if ( c=='2' ) i=2;if ( c=='3' ) i=3; if ( c=='4' ) i=4;if ( c=='5' ) i=5;if ( c=='6' ) i=6;if ( c=='7' ) i=7; if ( c=='8' ) i=8;if ( c=='9' ) i=9;if ( c=='A' ) i=10;if ( c=='B' ) i=11; if ( c=='C' ) i=12;if ( c=='D' ) i=13;if ( c=='E' ) i=14;if ( c=='F' ) i=15; if ( c=='G' ) i=16;if ( c=='H' ) i=17;if ( c=='I' ) i=18;if ( c=='J' ) i=19; if ( c=='K' ) i=20;if ( c=='L' ) i=21;if ( c=='M' ) i=22;if ( c=='N' ) i=23; if ( c=='O' ) i=24;if ( c=='P' ) i=25;if ( c=='Q' ) i=26;if ( c=='R' ) i=27; if ( c=='S' ) i=28;if ( c=='T' ) i=29;if ( c=='U' ) i=30;if ( c=='V' ) i=31; dig=i; if (test==0) printf( " \n\n CH=%c dig=%d \n\n", CH,dig ); return 0;} int SP021(void) { char P,Q,p[100],b[100],q[100]; int i,iP,pN,pp,D,DD,pq,jP,bN,qN; P=getchar();if ( P=='!') return 0; printf( "INPUT NUMBER SYSTEM P = "); P=getchar(); if ( P=='2' ) { iP=2;printf(" P = %c = (00010) \n\n",P);} if ( P=='3' ) { iP=3;printf(" P = %c = (00011) \n\n",P);} if ( P=='4' ) { iP=4;printf(" P = %c = (00100) \n\n",P);} if ( P=='5' ) { iP=5;printf(" P = %c = (00101) \n\n",P);} if ( P=='6' ) { iP=6;printf(" P = %c = (00110) \n\n",P);} if ( P=='7' ) { iP=7;printf(" P = %c = (00111) \n\n",P);} if ( P=='8' ) { iP=8;printf(" P = %c = (01000) \n\n",P);} if ( P=='9' ) { iP=9;printf(" P = %c = (01001) \n\n",P);} if ( P=='A' ) { iP=10;printf(" P = %c = (01010) = 10 \n\n",P);} if ( P=='B' ) { iP=11;printf(" P = %c = (01011) = 11 \n\n",P);} if ( P=='C' ) { iP=12;printf(" P = %c = (01100) = 12 \n\n",P);} if ( P=='D' ) { iP=13;printf(" P = %c = (01101) = 13 \n\n",P);} if ( P=='E' ) { iP=14;printf(" P = %c = (01110) = 14 \n\n",P);} if ( P=='F' ) { iP=15;printf(" P = %c = (01111) = 15 \n\n",P);} if ( P=='G' ) { iP=16;printf(" P = %c = (10000) = 16 \n\n",P);} if ( P=='H' ) { iP=17;printf(" P = %c = (10001) = 17 \n\n",P);} if ( P=='I' ) { iP=18;printf(" P = %c = (10010) = 18 \n\n",P);} if ( P=='J' ) { iP=19;printf(" P = %c = (10011) = 19 \n\n",P);} if ( P=='K' ) { iP=20;printf(" P = %c = (10100) = 20 \n\n",P);} if ( P=='L' ) { iP=21;printf(" P = %c = (10101) = 21 \n\n",P);} if ( P=='M' ) { iP=22;printf(" P = %c = (10110) = 22 \n\n",P);} if ( P=='N' ) { iP=23;printf(" P = %c = (10111) = 23 \n\n",P);} if ( P=='O' ) { iP=24;printf(" P = %c = (11000) = 24 \n\n",P);} if ( P=='P' ) { iP=25;printf(" P = %c = (11001) = 25 \n\n",P);} if ( P=='Q' ) { iP=26;printf(" P = %c = (10100) = 26 \n\n",P);} if ( P=='R' ) { iP=27;printf(" P = %c = (10101) = 27 \n\n",P);} if ( P=='S' ) { iP=28;printf(" P = %c = (10110) = 28 \n\n",P);} if ( P=='T' ) { iP=29;printf(" P = %c = (10111) = 29 \n\n",P);} if ( P=='U' ) { iP=30;printf(" P = %c = (11000) = 30 \n\n",P);} if ( P=='V' ) { iP=31;printf(" P = %c = (11001) = 31 \n\n",P);} jP=iP;P=getchar();if ( P=='!') return 0; printf("OUTPUT NUMBER SYSTEM Q = "); P=getchar(); if ( P=='2' ) { iP=2;printf(" Q = %c = (00010) \n\n",P);} if ( P=='3' ) { iP=3;printf(" Q = %c = (00011) \n\n",P);} if ( P=='4' ) { iP=4;printf(" Q = %c = (00100) \n\n",P);} if ( P=='5' ) { iP=5;printf(" Q = %c = (00101) \n\n",P);} if ( P=='6' ) { iP=6;printf(" Q = %c = (00110) \n\n",P);} if ( P=='7' ) { iP=7;printf(" Q = %c = (00111) \n\n",P);} if ( P=='8' ) { iP=8;printf(" Q = %c = (01000) \n\n",P);} if ( P=='9' ) { iP=9;printf(" Q = %c = (01001) \n\n",P);} if ( P=='A' ) { iP=10;printf(" Q = %c = (01010) = 10 \n\n",P);} if ( P=='B' ) { iP=11;printf(" Q = %c = (01011) = 11 \n\n",P);} if ( P=='C' ) { iP=12;printf(" Q = %c = (01100) = 12 \n\n",P);} if ( P=='D' ) { iP=13;printf(" Q = %c = (01101) = 13 \n\n",P);} if ( P=='E' ) { iP=14;printf(" Q = %c = (01110) = 14 \n\n",P);} if ( P=='F' ) { iP=15;printf(" Q = %c = (01111) = 15 \n\n",P);} if ( P=='G' ) { iP=16;printf(" Q = %c = (10000) = 16 \n\n",P);} if ( P=='H' ) { iP=17;printf(" Q = %c = (10001) = 17 \n\n",P);} if ( P=='I' ) { iP=18;printf(" Q = %c = (10010) = 18 \n\n",P);} if ( P=='J' ) { iP=19;printf(" Q = %c = (10011) = 19 \n\n",P);} if ( P=='K' ) { iP=20;printf(" Q = %c = (10100) = 20 \n\n",P);} if ( P=='L' ) { iP=21;printf(" Q = %c = (10101) = 21 \n\n",P);} if ( P=='M' ) { iP=22;printf(" Q = %c = (10110) = 22 \n\n",P);} if ( P=='N' ) { iP=23;printf(" Q = %c = (10111) = 23 \n\n",P);} if ( P=='O' ) { iP=24;printf(" Q = %c = (11000) = 24 \n\n",P);} if ( P=='P' ) { iP=25;printf(" Q = %c = (11001) = 25 \n\n",P);} if ( P=='Q' ) { iP=26;printf(" Q = %c = (10100) = 26 \n\n",P);} if ( P=='R' ) { iP=27;printf(" Q = %c = (10101) = 27 \n\n",P);} if ( P=='S' ) { iP=28;printf(" Q = %c = (10110) = 28 \n\n",P);} if ( P=='T' ) { iP=29;printf(" Q = %c = (10111) = 29 \n\n",P);} if ( P=='U' ) { iP=30;printf(" Q = %c = (11000) = 30 \n\n",P);} if ( P=='V' ) { iP=31;printf(" Q = %c = (11001) = 31 \n\n",P);} pq=iP;iP=jP;jP=pq; if( test == 0 ) printf("\n\n iP=%d \n\n",iP); pN=1; Q=getchar(); if( Q == '!') return 0; printf("Give p="); NEXTP: p[0]=getchar(); if( p[0]=='?') goto NEXT; for (i=0;i"); cc=getchar(); if ( cc == '!' ) return 0; cc=getchar(); if ( cc =='+' ) { printf("B=");scanf("%lf",&B); A=A+B;printf("\nA=A+B=%f",A); goto NEXT;} if ( cc =='-' ) { printf("B=");scanf("%lf",&B); A=A-B;printf("\nA=A-B=%f",A); goto NEXT;} if ( cc =='*' ) { printf("B=");scanf("%lf",&B); A=A*B;printf("\nA=A*B=%f",A);goto NEXT; } if ( cc =='/' ) { printf("B=");scanf("%lf",&B); A=A/B;printf("\nA=A/B=%f",A); goto NEXT;} if ( cc =='s' ) { A=A*A; printf("\nA=A*A=%f",A);goto NEXT; } if ( cc =='r' ) { A=sqrt(A); printf("\nA=sqrt(A)=%f",A); goto NEXT;} if ( cc =='e' ) { A=exp(A); printf("\nA=exp(A)=%f",A);goto NEXT; } if ( cc =='n' ) { A=log(A); printf("\nA= Natural log(A) = %f",A);goto NEXT; } if ( cc =='l' ) { A=log(A)/log(10); printf("\nA=log(A) of base 10 = %f",A); goto NEXT;} if ( cc =='1' ) { printf("B=");scanf("%lf",&B);printf("X=");scanf("%lf",&X); printf("\nf(X)=A*X+B=%f",A*X+B); goto NEXT; } if ( cc =='2' ) { printf("B=");scanf("%lf",&B);printf("C=");scanf("%lf",&C); printf("X=");scanf("%lf",&X); printf("\nf(X)=A*X*X+B*X+C=%f",A*X*X+B*X+C);goto NEXT; } if ( cc =='A' ) goto NEXTA; printf("\n\n");return 0; NEXT: printf("\n\n");goto NEXTT;} /**************************************************************************/ /************************ SP014 **************************************** int SP014(void) 10to2 *************************************************************************/ int SP014(void) { int n,nn,i,m,k,A[25],C[25],D[25],E[25],B[200];char j; j=getchar(); if ( j == 'x' ) return 0 ; printf("\n******* Decimal to Binary ****************\n\n");n=1; printf(" Give Decimal Number = ");MOREC:j=getchar(); if ( j == '1' ) goto NEXTSTEP1;if ( j == '2' ) goto NEXTSTEP2; if ( j == '3' ) goto NEXTSTEP3;if ( j == '4' ) goto NEXTSTEP4; if ( j == '5' ) goto NEXTSTEP5;if ( j == '6' ) goto NEXTSTEP6; if ( j == '7' ) goto NEXTSTEP7;if ( j == '8' ) goto NEXTSTEP8; if ( j == '9' ) goto NEXTSTEP9;if ( j == '0' ) goto NEXTSTEP0;goto FINALD; NEXTSTEP0: D[n]=0;goto NEXTSTEP; NEXTSTEP1: D[n]=1;goto NEXTSTEP; NEXTSTEP2: D[n]=2;goto NEXTSTEP; NEXTSTEP3: D[n]=3;goto NEXTSTEP; NEXTSTEP4: D[n]=4;goto NEXTSTEP; NEXTSTEP5: D[n]=5;goto NEXTSTEP; NEXTSTEP6: D[n]=6;goto NEXTSTEP; NEXTSTEP7: D[n]=7;goto NEXTSTEP; NEXTSTEP8: D[n]=8;goto NEXTSTEP; NEXTSTEP9: D[n]=9;NEXTSTEP:n=n+1;goto MOREC; FINALD:n=n-1;m=-1; MNEXT:E[1]=D[1]; for (i=1;i< n;i++){C[i]=E[i]/2;A[i]=E[i]-2*C[i];E[i+1]=10*A[i]+D[i+1];} C[n]=E[n]/2;A[n]=E[n]-2*C[n];m=m+1;B[m]=A[n]; k=0; for (i=1;i<=n;i++) { D[i]=C[i];if(D[i]!=0) k=1;} if(k==1) goto MNEXT; FINAL: printf("\n m=%d Binary Number = ",m); for (i=0;i<=m;i++) printf("%d",B[m-i]); printf("\n\n******************************************\n"); j=getchar();if ( j == 'X' ) return 0 ; j=getchar();if ( j == 'X' ) return 0 ; printf("\n\n*** End of 10to2 ***\n\n\n\n"); return 0;} /**********************************************************************/ /************************ SP013 **************************************** int SP013(void) 2to10 *************************************************************************/ int SP013(void) { int n,i,m,k,Deci,D[200],B[200];char j; printf("\n\n******* Binary to Decimal ****************\n\n");n=1; j=getchar(); if ( j == 'x' ) return 0 ; MORE: printf(" Give Binary Number = "); MOREC:j=getchar(); if ( j == '1' ) goto NEXTSTEP1;if ( j == '0' ) goto NEXTSTEP0;goto FINALD; NEXTSTEP0: D[n]=0;goto NEXTSTEP; NEXTSTEP1: D[n]=1; NEXTSTEP:n=n+1;goto MOREC; FINALD:m=n-2;for(i=0;i<=m;i++) B[m-i]=D[i+1];Deci=B[0];k=1; for (i=1;i<=m;i++) { k=2*k;Deci=Deci+k*B[i]; } printf("\n Decimal Number =%d",Deci); printf("\n\n******************************************\n"); j=getchar();if ( j == 'X' ) goto MORE; printf("\n\n*** End of 2to10 ***\n\n\n\n"); return 0;} /******************************************************************/ /****************************************************************** int SP012(void) 2jishiki ******************************************************************/ /*********************** SP012 *************************/ /* */ /* This program computes the roots of */ /* */ /* ax*x+bx+c = 0 */ /* */ /*******************************************************/ int SP012(void) { double a,b,c,BA,BB,CA,DD,D,X1,X2,Y1,Y2; int more; MOREX: printf("\na=");scanf("%lf",&a);printf(" %f\n",a); printf("\nb=");scanf("%lf",&b);printf(" %f\n",b); printf("\nc=");scanf("%lf",&c);printf(" %f\n",c); BA=b/2/a;BB=BA*BA;CA=c/a;DD=BB-CA; if ( DD == 0 ) goto JUKON;if ( DD < 0 ) goto KYOSU; D=sqrt(DD); X1=-BA+D; X2=-BA-D;Y1=0,Y2=0; goto NEXT; JUKON: X1= -BA ; X2=X1; Y1=0;Y2=0; goto NEXT; KYOSU: D=sqrt(-DD); X1= -BA; X2=X1; Y1=D;Y2=-D; NEXT: printf(" \n X1=%f Y1=%f\n", X1,Y1); printf(" X2=%f Y2=%f\n", X2,Y2); printf("\n MORE ? ");scanf("%d", &more); if ( more == 1 ) goto MOREX; printf("\n\n*** End of 2jishiki ***\n\n\n\n"); return 0;} /*******************************************************/ /******************************************************* int CheckG06(void) Now check whether A3 is in the 5th generation List of OYA(iset) = A4. If found, set FINISH=1 and  printf "Yes, A3 is A4. ( The 5th Generation ) " If not found, set FINISH=0 and return *******************************************************/ int CheckG06(void) { return 0; } /******************************************************* int CheckG05(void) Now check whether A3 is in the 5th generation List of OYA(iset) = A4. If found, set FINISH=1 and  printf "Yes, A3 is A4. ( The 5th Generation ) " If not found, set FINISH=0 and return *******************************************************/ int CheckG05(void) { return 0; } /******************************************************* int CheckG04(void) Now check whether A3 is in the 4th generation List of OYA(iset) = A4. If found, set FINISH=1 and  printf "Yes, A3 is A4. ( The 4th Generation ) " If not found, set FINISH=0 and return *******************************************************/ int CheckG04(void) { return 0; } /******************************************************* int CheckHimago(void) Now check whether A3 is in the Mago List of OYA(iset) = A4. If found, set FINISH=1 and  printf "Yes, A3 is A4. ( Himago Generation ) " If not found, set FINISH=0 and return *******************************************************/ int CheckHimago(void) { return 0; } /*********************************************************************      関数 int CheckOya(void) の定義の中で出力 data が                   data base file名 ( AIPS001LK.txt )            に書き込まれます             int CheckOya(void) { int ikid,jkid,lenOYA,iY;        FILE *fpA;fpA=fopen("AIPS001LK.txt","r");                        。。。。。。 とあります。 *********************************************************************/ /******************************************************* int CheckOya(void) This program checks whether SOYA is in OYA LINK list. If not found, set OYAflag = 0 If found, set OYAflag = 1 If found, the iset of OYA = SOYA . *******************************************************/ int CheckOya(void) { int ikid,jkid,lenOYA,iY; FILE *fpA;fpA=fopen("AIPS001LK.txt","r"); if( test == 0) printf ( "\n\n CheckOya() called \n\n"); if( test == 0) printf ( "\n\n Level = %d \n\n",Level); if( test == 0) printf ( "\n\n looking for SOYA =%s ... \n\n",SOYA); fscanf(fpA,"%d",&nset); for (iset=1;iset " ); c1=getchar(); c2=getchar(); if(c1!='y') goto FINALB; if(c2!='e') goto FINALB; c3=getchar();if(c3!='s') goto FINALB; ADDOYA();COPYLINK(); printf("\n\n Now I know %s is %s .... \n\n", A2,A4); BYE=2;return 0; FINALB: printf ("\n\n O.K.... i just forget it .... \n\n" ); BYE=2;return 0; } checkkidA2(); if( NoCheckA2==0 ) { c1=getchar(); printf("\n\n Really ? Is %s %s ? \n\n", A2,A4); printf(" if so, please type yes --> " ); c1=getchar(); c2=getchar(); if(c1!='y') goto FINALA; if(c2!='e') goto FINALA; c3=getchar();if(c3!='s') goto FINALA; ADDkidA2();COPYLINK(); printf("\n\n Now I know %s is %s .... \n\n", A2,A4); BYE=2;return 0;} printf("\n\n I knew %s is %s .... \n\n", A2,A4); BYE=2;return 0; FINALA: printf ("\n\n O.K.... i just forget it .... \n\n" ); BYE=2;return 0; } int CTASK(void) { printf("\n\nP%s = ",SP); printf("%s \n\n",B); iSP=0;i=2;j=1; for (i=0;i<3;i++) { if(SP[2-i]=='1') iSP=iSP+1*j; if(SP[2-i]=='2') iSP=iSP+2*j; if(SP[2-i]=='3') iSP=iSP+3*j; if(SP[2-i]=='4') iSP=iSP+4*j; if(SP[2-i]=='5') iSP=iSP+5*j; if(SP[2-i]=='6') iSP=iSP+6*j; if(SP[2-i]=='7') iSP=iSP+7*j; if(SP[2-i]=='8') iSP=iSP+8*j; if(SP[2-i]=='9') iSP=iSP+9*j; j=j*10;} if ( iSP==12) SP012(); if ( iSP==13) SP013(); if ( iSP==14) SP014(); if ( iSP==20) SP020(); if ( iSP==21) SP021(); return 0; } int readA(void) { i=1; scanf("%s",&A1);lenA1=strlen(A1); for ( j=0;j<10;j++) if (A1[j]==',') goto FINAL; for ( j=0;j<10;j++) if (A1[j]=='!') goto FINAL; for ( j=0;j<10;j++) if (A1[j]=='.') goto FINAL; for ( j=0;j<10;j++) if (A1[j]=='?') goto FINAL; i=2; scanf("%s",&A2);lenA2=strlen(A2); for ( j=0;j<10;j++) if (A2[j]==',') goto FINAL; for ( j=0;j<10;j++) if (A2[j]=='!') goto FINAL; for ( j=0;j<10;j++) if (A2[j]=='.') goto FINAL; for ( j=0;j<10;j++) if (A2[j]=='?') goto FINAL; i=3; scanf("%s",&A3);lenA3=strlen(A3); for ( j=0;j<10;j++) if (A3[j]==',') goto FINAL; for ( j=0;j<10;j++) if (A3[j]=='!') goto FINAL; for ( j=0;j<10;j++) if (A3[j]=='.') goto FINAL; for ( j=0;j<10;j++) if (A3[j]=='?') goto FINAL; i=4; scanf("%s",&A4);lenA4=strlen(A4); for ( j=0;j<10;j++) if (A4[j]==',') goto FINAL; for ( j=0;j<10;j++) if (A4[j]=='!') goto FINAL; for ( j=0;j<10;j++) if (A4[j]=='.') goto FINAL; for ( j=0;j<10;j++) if (A4[j]=='?') goto FINAL; i=5; scanf("%s",&A5);lenA5=strlen(A5); for ( j=0;j<10;j++) if (A5[j]==',') goto FINAL; for ( j=0;j<10;j++) if (A5[j]=='!') goto FINAL; for ( j=0;j<10;j++) if (A5[j]=='.') goto FINAL; for ( j=0;j<10;j++) if (A5[j]=='?') goto FINAL; i=6; scanf("%s",&A6);lenA6=strlen(A6); for ( j=0;j<10;j++) if (A6[j]==',') goto FINAL; for ( j=0;j<10;j++) if (A6[j]=='!') goto FINAL; for ( j=0;j<10;j++) if (A6[j]=='.') goto FINAL; for ( j=0;j<10;j++) if (A6[j]=='?') goto FINAL; i=7; scanf("%s",&A7);lenA7=strlen(A7); for ( j=0;j<10;j++) if (A7[j]==',') goto FINAL; for ( j=0;j<10;j++) if (A7[j]=='!') goto FINAL; for ( j=0;j<10;j++) if (A7[j]=='.') goto FINAL; for ( j=0;j<10;j++) if (A7[j]=='?') goto FINAL; i=8; scanf("%s",&A8);lenA8=strlen(A8); for ( j=0;j<10;j++) if (A8[j]==',') goto FINAL; for ( j=0;j<10;j++) if (A8[j]=='!') goto FINAL; for ( j=0;j<10;j++) if (A8[j]=='.') goto FINAL; for ( j=0;j<10;j++) if (A8[j]=='?') goto FINAL; i=9; scanf("%s",&A9);lenA9=strlen(A9); for ( j=0;j<10;j++) if (A9[j]==',') goto FINAL; for ( j=0;j<10;j++) if (A9[j]=='!') goto FINAL; for ( j=0;j<10;j++) if (A9[j]=='.') goto FINAL; for ( j=0;j<10;j++) if (A9[j]=='?') goto FINAL; printf("\n\n Too Many Words...\n\n"); BYE=1; return 0; FINAL: k=i; if( test== 0 ) { printf("\n\n"); if(098 ) { fprintf(fpB,"%d\n\n",NSS+1);goto NEXTCD;} if ( NSS >8 ) { fprintf(fpB,"0%d\n\n",NSS+1);goto NEXTCD;}; fprintf(fpB,"00%d\n\n",NSS+1); NEXTCD: cc=getchar(); printf("\n If you say, "); readA();if (BYE==1) return 0; if ( k>=1) { fprintf(fpB,"%s ",A1);if(test==0) printf("%s ",A1); } if ( k>=2) { fprintf(fpB,"%s ",A2);if(test==0) printf("%s ",A2); } if ( k>=3) { fprintf(fpB,"%s ",A3);if(test==0) printf("%s ",A3); } if ( k>=4) { fprintf(fpB,"%s ",A4);if(test==0) printf("%s ",A4); } if ( k>=5) { fprintf(fpB,"%s ",A5);if(test==0) printf("%s ",A5); } if ( k>=6) { fprintf(fpB,"%s ",A6);if(test==0) printf("%s ",A6); } if ( k>=7) { fprintf(fpB,"%s ",A7);if(test==0) printf("%s ",A7); } if ( k>=8) { fprintf(fpB,"%s ",A8);if(test==0) printf("%s ",A8); } if ( k>=9) { fprintf(fpB,"%s ",A9);if(test==0) printf("%s ",A9); } fprintf(fpB,"\n\n");if(test==0) printf("\n\n"); for ( i=1;i<10;i++) { for (j=0;j<10;j++) { B1[j]=A1[j];B2[j]=A2[j];B3[j]=A3[j];B4[j]=A4[j]; B5[j]=A5[j];B6[j]=A6[j];B7[j]=A7[j];B8[j]=A8[j];B9[j]=A9[j];}} kB=k; printf("\n I will say, "); readA();if (BYE==1) return 0; if ( k>=1) { fprintf(fpB,"%s ",A1);if(test==0) printf("\n\n %s ",A1); } if ( k>=2) { fprintf(fpB,"%s ",A2);if(test==0) printf("%s ",A2); } if ( k>=3) { fprintf(fpB,"%s ",A3);if(test==0) printf("%s ",A3); } if ( k>=4) { fprintf(fpB,"%s ",A4);if(test==0) printf("%s ",A4); } if ( k>=5) { fprintf(fpB,"%s ",A5);if(test==0) printf("%s ",A5); } if ( k>=6) { fprintf(fpB,"%s ",A6);if(test==0) printf("%s ",A6); } if ( k>=7) { fprintf(fpB,"%s ",A7);if(test==0) printf("%s ",A7); } if ( k>=8) { fprintf(fpB,"%s ",A8);if(test==0) printf("%s ",A8); } if ( k>=9) { fprintf(fpB,"%s ",A9);if(test==0) printf("%s ",A9); } fprintf(fpB,"\n\n");if(test==0) printf("\n\n"); fclose(fpA);fclose(fpB); printf("\n\nPlease confirm :"); printf("\n\n If you say, "); if ( kB>=1) printf("%s ",B1); if ( kB>=2) printf("%s ",B2); if ( kB>=3) printf("%s ",B3); if ( kB>=4) printf("%s ",B4); if ( kB>=5) printf("%s ",B5); if ( kB>=6) printf("%s ",B6); if ( kB>=7) printf("%s ",B7); if ( kB>=8) printf("%s ",B8); if ( kB>=9) printf("%s ",B9); printf("\n I will say, "); if ( k>=1) printf("%s ",A1); if ( k>=2) printf("%s ",A2); if ( k>=3) printf("%s ",A3); if ( k>=4) printf("%s ",A4); if ( k>=5) printf("%s ",A5); if ( k>=6) printf("%s ",A6); if ( k>=7) printf("%s ",A7); if ( k>=8) printf("%s ",A8); if ( k>=9) printf("%s ",A9); printf("\n\n");cc=getchar(); printf("If OK, please type yes or no > "); c1=getchar(); c2=getchar(); if(c1!='y') goto FINALA; if(c2!='e') goto FINALA; c3=getchar();if(c3!='s') goto FINALA; COPYDATA(); printf("\n\n CONFIRMED :"); printf("\n\n If you say, "); if ( kB>=1) printf("%s ",B1); if ( kB>=2) printf("%s ",B2); if ( kB>=3) printf("%s ",B3); if ( kB>=4) printf("%s ",B4); if ( kB>=5) printf("%s ",B5); if ( kB>=6) printf("%s ",B6); if ( kB>=7) printf("%s ",B7); if ( kB>=8) printf("%s ",B8); if ( kB>=9) printf("%s ",B9); printf("\n\n I will say, "); if ( k>=1) printf("%s ",A1); if ( k>=2) printf("%s ",A2); if ( k>=3) printf("%s ",A3); if ( k>=4) printf("%s ",A4); if ( k>=5) printf("%s ",A5); if ( k>=6) printf("%s ",A6); if ( k>=7) printf("%s ",A7); if ( k>=8) printf("%s ",A8); if ( k>=9) printf("%s ",A9); printf("\n\n"); FINALA: cc=getchar(); printf("\n\n");BYE=2;return 0; } /**************************************************************** int checkCAA(void) ***************************************************************** given { C of ISS and AA of (ISS,jA) } ; check C of ISS and AA of (ISS,jA); if ( C includes AA ) { set recogA=1 ;return 0 } otherwise { recogA=0 ;return 0 } ****************************************************************/ int checkCAA(void) { if( test== 0 ) { printf("\n\ncheckCAA ISS=%d :checking C and AA \n\n",ISS); printf(" lenC=%d C=%s\n\n",lenC,C); printf(" lenA=%d AA=%s\n\n",lenA,AA); cc=getchar(); } iC=0;jA=0;recogA=0; NEXTjA: if( test== 0 ) { printf("\n\n jA =%d iC=%d \n\n",jA,iC); printf (" AA[jA]=%c C[iC]=%c \n\n",AA[jA],C[iC]); cc=getchar();} if ( C[iC] == AA[jA] ) { iC=iC+1; jA=jA+1; if (jA == lenA) { if( test== 0 ) { printf("\n\nMatched iA=%d iC=%d \n\n",iA,iC); printf(" lenC=%d C=%s\n\n",lenC,C); printf(" lenA=%d AA=%s\n\n",lenA,AA); cc=getchar();} recogA=1;return 0;} goto NEXTjA; } iC=iC+1; if ( iC > lenC ) { if( test== 0 ) { printf("\n\n No Match ISS=%d \n\n",ISS);cc=getchar();} recog = 0; return 0; } goto NEXTjA; } /************************************************************** int checkA(void) *************************************************************** for each iA=1 to (k-1) { set AA = (AA of iA); lenA = (lenA of iA); } checkCAA();return 0; **************************************************************/ int checkA(void) { if( iA >= k ) return 0; if (iA ==1 ) for ( i=0;i<10;i++) { AA[i]=A1[i];lenA=lenA1;} if (iA ==2 ) for ( i=0;i<10;i++) { AA[i]=A2[i];lenA=lenA2;} if (iA ==3 ) for ( i=0;i<10;i++) { AA[i]=A3[i];lenA=lenA3;} if (iA ==4 ) for ( i=0;i<10;i++) { AA[i]=A4[i];lenA=lenA4;} if (iA ==5 ) for ( i=0;i<10;i++) { AA[i]=A5[i];lenA=lenA5;} if (iA ==6 ) for ( i=0;i<10;i++) { AA[i]=A6[i];lenA=lenA6;} if (iA ==7 ) for ( i=0;i<10;i++) { AA[i]=A7[i];lenA=lenA7;} if (iA ==8 ) for ( i=0;i<10;i++) { AA[i]=A8[i];lenA=lenA8;} if (iA ==9 ) for ( i=0;i<10;i++) { AA[i]=A9[i];lenA=lenA9;} checkCAA(); return 0;} /***************************************************************** int compare(void) ****************************************************************** for iA = 1 to k { checkA() ;} if ( recogA == 0 ) return 0; otherwise {recog=1; return 0;} *****************************************************************/ int compare(void){ iA=1; if(iANSS) goto FINAL; goto NEXTH; FINAL: fclose(fpA);return 0;} /******************************************************************** int readline(void) ********************************************************************* (1) Obtain the command ( A1 A2 A3 A4 A5 A6 A7 A8 A9 ); These 9 words are the ordered command key words. The commmand key words must be less than 10 words. { k = # of command key words: if k = 3, (A1,A,A3) are read; } A[k] must be either one of '?','/' '!' and ',' ; Only A[1] to A[k-1] are used as the command key words; (2) If A1='BYE', program ends. { BYE=1 ; return 0; } (3) If (A1 A2 A3)='If i say,' NewCMD() is called. NewCMD() replies 'If you say, 'what shall I say ? then obtains a new command line and its reply line. (4) if (BYE != 1) set BYE=2; return 0 ; } *********************************************************************/ int readline(void) { printf("AIPS-->");readA(); if( BYE==1) { printf("\n\n Good-bye ! \n\n>");return 0;} recog=0; BYE=0; if( A1[0] !='B') goto AAA; if( A1[1] !='Y') goto AAA; if( A1[2] !='E') goto AAA; BYE=1; printf("\n\n Good-bye ! \n\n>");return 0; AAA: if( A1[0] !='i') goto NOTE; if( A1[1] !='f') goto NOTE; if( A2[0] !='i') goto NOTE; if( A3[0] !='s') goto NOTE; if( A3[1] !='a') goto NOTE; if( A3[2] !='y') goto NOTE; if( A3[3] !=',') goto NOTE; MORE:NewCMD(); if ( BYE == 1) { cc=getchar();cc=getchar();return 0; } printf(" MORE=");scanf("%d",&i); if( i==1 ) goto MORE; cc=getchar();cc=getchar();return 0 ; NOTE: if( A1[0] !='N') goto LINK; if( A1[1] !='O') goto LINK; if( A1[2] !='T') goto LINK; if( A1[3] !='E') goto LINK; if (test==0) printf("\n\n ***Entering NOTE() from readline() **** \n\n"); NOTE(); cc=getchar();cc=getchar();return 0 ; LINK: if( A1[0] !='L') goto FINAL; if( A1[1] !='I') goto FINAL; if( A1[2] !='N') goto FINAL; if( A1[3] !='K') goto FINAL; if (test==0) printf("\n\n ***Entering LINK() from readline() **** \n\n"); cc=getchar();LINK(); cc=getchar();cc=getchar();return 0 ; FINAL: if (test==0) printf("\n\n ***Reached FINAL @readline() **** \n\n"); cc=getchar();cc=getchar();return 0 ;} /******************************************************************** int main(void) ********************************************************************* (1) Type, Hello, how are you ? (2) Set { BYE=0; norecog=0; } (3) readline(); read the command line. (4) If the command is 'BYE !' { BYE=1 and the program ends.} (5) If the command is 'if i say,' { NewCMD();BYE=2; goto (2);} (6) If BYE =0 { check the command line...check(); } (7) If BYE=3, goto (2); (8) If recog is 0, { set norecog=norecog+1;and write I don't understand... } (9) If norecog < 2, goto step (2). (10) If norecog = 2 , program ends with a good-bye message. BYE=1 if the command line = BYE ! BYE=2 if the command line = if i say, BYE=3 if the command line = C-program 000p *********************************************************************/ int main(void){ printf("\n\n************ HelloAIPS *****************\n\n"); printf(" Hello, how are you ? \n\n"); printf("****************************************\n\n"); NEXTA:norecog=0;BYE=0; NEXT: readline(); if( BYE == 1 ) { cc=getchar();cc=getchar();return 0;} if( BYE == 2 ) {BYE=0;goto NEXT;} recog=0;BYE=0;check(); if (BYE == 3) { BYE=0; goto NEXT;} if(recog == 0 ) { norecog=norecog+1; printf("\n I don't understand...\n\n");} if (norecog < 2) goto NEXT; if ( k==0 ) printf(" \n\n Bye.... \n\n"); if ( k==1 ) printf(" \n\n Good-bye. \n\n"); if ( k==2 ) printf(" \n\n Have a nice day. \n\n"); if ( k==3 ) printf(" \n\n Please take care. \n\n"); if ( k >3 ) printf(" \n\n See you soon again. \n\n"); cc=getchar();cc=getchar();return 0; }