Прикол в том что ты можешь в файл писать и без пробела и спробелом и в несколько строк
| Цитата | 0:: #include<stdio.h> 1:: #include<io.h> 2:: #include<conio.h> 3:: #include<fstream.h> 4:: #include<iostream.h> 5:: 6:: #define NLINE 0 7:: #define NSYMB 1 8:: #define VALUE 2 9:: 10:: #define MAXSZ 1024 11:: 12:: 13:: static int minq[ 3 ]={-1,-1,-1}, maxq[ 3 ]={-1,-1,-1}, linecount; 14:: 15:: 16:: void report() 17:: { 18:: cout << "\nReport:\tFile t.txt\tLine -- " << linecount << endl; 19:: if( minq[ VALUE ]>-1 ) 20:: { 21:: cout << "Minimum Value: "; 22:: cout << "Line( " << minq[ NLINE ] << " ) Symbol Number( " << minq[ NSYMB ]+1 << " )" 23:: << "Value( " << minq[ VALUE ]-'0' << " )" << endl; 24:: } 25:: if( maxq[ VALUE ]>-1 ) 26:: { 27:: cout << "Maximum Value: "; 28:: cout << "Line( " << maxq[ NLINE ] << " ) Symbol Number( " << maxq[ NSYMB ]+1 << " )" 29:: << "Value( " << maxq[ VALUE ]-'0' << " )" << endl; 30:: } 31:: return; 32:: } 33:: 34:: 35:: void MinMax( fstream &IN ) 36:: { 37:: int i, j, ch; 38:: char buf[ MAXSZ ], *p; 39:: 40:: 41:: IN.seekp( 0, ios::beg ); 42:: IN.width( sizeof(buf) ); 43:: for( linecount=0; !IN.eof(); ) 44:: { 45:: if( IN.eof() ) 46:: break; 47:: if( IN.getline(buf, MAXSZ) && (strlen(buf)>0) ) 48:: { 49:: ++linecount; 50:: p=buf; 51:: 52:: minq[ VALUE ]=p[ 0 ]; 53:: maxq[ VALUE ]=p[ 0 ]; 54:: for( i=0, j=0; *p; p++, i++ ) 55:: { 56:: if( *p==' ' ) 57:: continue; 58:: ++j; 59:: if( *p<minq[ VALUE ] ) 60:: { 61:: minq[ NLINE ]=linecount; 62:: minq[ NSYMB ]=j; 63:: minq[ VALUE ]=*p; 64:: } 65:: if( *p>maxq[ VALUE ] ) 66:: { 67:: maxq[ NLINE ]=linecount; 68:: maxq[ NSYMB ]=j; 69:: maxq[ VALUE ]=*p; 70:: } 71:: } 72:: report(); 73:: } 74:: } 75:: return; 76:: } 77:: 78:: 79:: int main() 80:: { 81:: 82:: fstream t; 83:: 84:: t.open( ".\\t.txt", ios::in ); 85:: if( !t ) 86:: { 87:: cout << "Can`t open file!" << endl; 88:: return 1; 89:: } 90:: 91:: MinMax( t ); 92:: 93:: return 0; 94:: } 95:: 96::
|
|