wc and reading from pipe

Hi. I want to give files and get the highest byte from the files. My code is working only for one ile giving the byte but when I give two it gives 1

my files hello.txt with word hello
and helloa.txt with word helloa

1
2
3
4
5
6
7
8
9
10
11
12
13
else if ((strcmp(argv[i], "-b")==0)){

            prev=next;
            cout<<"PREV: "<<prev<<endl;

            next=file[4];
            cout<<"NEXT: "<<next<<endl;

            //int Num=(num);
            if(prev.compare(next)<0)
                biggest=next;

            cout<<file[4]<<" BIIGEST: "<<biggest<<endl;


output is 1
Not enough context to see the problem.
Your program should read the output of wc as standard input. In another words, the program is to behave as if it were part of the pipeline. Typical execution would be

wc demofile.txt | your_program -[b | w | l]

where your_program is your executable program which will take in the

std::out of wc demofile.txt command as std::in of your program.

The [b | w | l] is the option pass as

command line argument to your program which indicate bytes count, words count or lines count respectively. After reading the inputs, your program should generate a summary report which contains the following information as in the example below:

Example 1:

$ wc demofile.txt | ./program -b
1) The number of files : 1
2) The largest file in byte : demofile.txt (7148 bytes)
3) The smallest file in byte : demofile.txt (7148 bytes) 4) The total number of bytes : 7148 bytes

Example 2:

$ wc *.h | ./program -l
1) The number of files : 6
2) The largest file in line : libaw.h (115 lines) 3) The smallest file in line : mesa.h (39 lines) 4) The total number of lines : 347 lines
That seems to continue: http://www.cplusplus.com/forum/unices/159802/

Your code contains unexplained identifiers: prev, next, file.

I do recommend that you first read and store all input. You should then have a nice array. From that array you can query the necessary details, as requested by the command line argument. Surely you do know how to find the maximum value from an array?

More in: http://www.cplusplus.com/forum/unices/161339/
but files output from pipe may vary...it will be a constraint to size the array to a limit and not what the demand of output may say
it will be a constraint to size the array to a limit

That is why you should not use an array, but a dynamically resizing container, such as std::vector. No constraint.
hmmm, vector comes much late in our course :(...thank for the help though.
No vector then.

Are you allowed to understand what the following program does?
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <limits>

int main () {
  double max { std::numeric_limits<double>::min() };
  double value { 0.0 };
  while ( std::cin >> value )
  {
    if ( max < value ) max = value;
  }
  std::cout << "Largest value was: " << max << '\n';
  return 0;
}
didn't cover generic yet :(...but thanks I will keep these examples for future reference
Topic archived. No new replies allowed.