| Код | #include <stdio.h> #include <fstream.h> #include <string.h> #include <conio.h> #include <iostream.h>
void SaveText() { FILE *f = fopen("text.dat","w"); fprintf( f, "int main () { clrscr () ; SaveText () ;\n" ); fprintf( f, "char text [100][20] ; char slovo [20] ; ifstream\n" ); fprintf( f, "if ( ! fin ) { cout << Error open file ! << endl ;\n" ); fprintf( f, "return 1 ; } int kolvo = out ( fin , text ) ;\n" ); fprintf( f, "for ( int i = 0 ; i < kolvo ; i ++ ) { cout << text [i] ;}\n" ); fprintf( f, "cout << Vvedite slovo dla poiska ( 'end' -exit) > ; cin\n" ); fprintf( f, "if ( ! strcmp ( slovo , endl ) ) return 0 ;\n" ); fprintf( f, "char name [] = ERROR Otsutstvuet ! \n" ); fprintf( f, "for ( int i = 0; i < kolvo ; i ++ )\n" ); fprintf( f, "int c = strcmp ( text [i], slovo ) ; if ( !c )\n" ); fclose( f ); }; int out(ifstream &f, char text[][20]) { int i = 0; char c[20]; while( f>>c ) { memcpy(text[i],c,20); i++; } return i; }; void cop( char *c ) { char ch[20]; ch[0] = 34; ch[1]='\0'; strcat(ch,c); strcat(ch,"\""); strcpy(c, ch); }; int main() { clrscr(); SaveText(); char text[200][20]; char slovo[20]; ifstream fin("text.dat"); if (!fin) { cout << "Error open file! " <<endl; return 1; } int kolvo = out( fin, text ); fin.close(); while (1) { clrscr(); for ( int i=0; i<kolvo; i++ ) cout << text[i]<<" "; cout <<endl<<endl<< "Vvedite slovo dla poiska ('end'-exit) > "; cin >> slovo; if ( !strcmp(slovo,"end") ) break; char name[] = "ERROR Otsutstvuet! " ; for ( i=0; i<kolvo; i++ ) { int c = strcmp(text[i], slovo) ; if ( !c ) { strcpy(name, "OK. Prisutstvue! "); cop(text[i]); } } cout<<name; cout<<endl; } return 0; }
|
Чтобы и цыкла выйти "end" введи. |