1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
int main(int argc, char* argv[]){
int j=0,k=0;
string file;
char *file1=new char[80];
char *fsize=NULL, fileWordMax[20], fileLineMax[20], fileByteMax[20];
int maxByte=0, maxWord=0, maxLine=0, count=0;
while (getline (cin, file)!=NULL){
strcpy (file1, file.c_str()); //convert str to C style string (char array)
fsize=strtok(file1, " ");
if(atoi(fsize)>maxLine){
maxLine=atoi(fsize);
for(int j=0;j<file.length();j++){
if(isalpha(file[j])){
//cout<<file[j]<<endl;
fileLineMax[k]=file[j];
k++;
}
}
for(int i=1;i<2;i++){
fsize=strtok(NULL, " ");
if(atoi(fsize)>maxWord){
maxWord=atoi(fsize);
//strcpy(fileWordMax, file1);
}
}
for(int i=2;i<4;i++){
fsize=strtok(NULL, " ");
if(atoi(fsize)>maxByte){
maxByte=atoi(fsize);
//strcpy(fileWordMax, file1);
}
}
}
}
if(argc==1){
cout<<"insufficient arguments entered"<<endl;
return 0;}
for(int i=1;i<argc;i++){
if((strcmp(argv[i], "-l")==0)){
cout<<"Highest number of lines: "<<maxLine<<" in file "<</*fileLineMax*/<<endl;
}
|