#include<string> #include<iostream> #include<fstream> #include<cstdlib> #define SYMBOLS 0 #define WORDS 1 #define STRINGS 2 #define NSTRING 3 #define NWORD 4 #define OVERLEN 5 using namespace std; int main(int argc, char **argv){ int i, j, cc; char buf[1001]; long count[6]={ -1, // count[ SYMBOLS ] - кол-во символов в файле 0, // count[ WORDS ] - кол-во слов 0, // count[ STRINGS ] - кол-во строк 0, // count[ NSTRING ] - номер строки в кот-ой самое длинное слово 0, // count[ NWORD ] - номер слова кот-е явл-ся самым длинным 0 //count[ OVERLEN ] - длина самого длинного слова }; fstream f; f.open(argv[1], ios::in | ios::out); if( !f ){ cout<<"Cannot open file : "<<argv[1]<<endl; exit(1); } f.seekp( 0, ios::beg); while(!f.eof()){ f.getline(buf,1000); puts(buf); if(strlen(buf) >0 ) ++count[STRINGS]; // строки else continue; for(i=0, j=0; i<= strlen(buf); ++i, ++j ){ if(buf[i]==' ' || buf[i]=='\t'|| buf[i]=='\n' || buf[i]=='\0' ){ for( ; i<=strlen(buf) && (buf[i] ==' ' || buf[i]=='\t'); ++i ); if(i>0){ ++count[WORDS]; // слова } if(j>count[OVERLEN]){ count[NWORD] = count[WORDS]; count[NSTRING] = count[STRINGS]; count[OVERLEN] = j; } j=0; } } count[SYMBOLS] +=i; } cout<<"SYMBOLS: "<<count[SYMBOLS]<<endl; cout<<"WORDS: "<<count[WORDS]<<endl; cout<<"STRINGS: "<<count[STRINGS]<<endl; return 0; }