This is my program,what I want is do this program to check how many bytes,lines and words inside any of the file.
When I type wc test.cpp it will pop out
6 111 12608 test
But when I type wc test.cpp | ./test -l
it give me segmentation fault(core dumped)
Anyone can help me with this?
This is my program,what I want is do this program to check how many bytes,lines and words inside any of the file.
When I type wc test.cpp it will pop out
6 111 12608 test
But when I type wc test.cpp | ./test -l
it give me segmentation fault(core dumped)
Anyone can help me with this?
I'll give you a hint.
You're running your program twice.
The first time, you run: wc test.cpp where argc = 2, argv = ["wc", "test.cpp"]
The second time, you run wc where argc = 2, argv = ["wc", "-l"] and the input comes in on stdin.
after I type wc test.cpp it will pop out the 3 num and 1 file name,example
12 12 50 test.cpp
after I type wc test.cpp | ./test -l
It not suppose to capture the 3 num and file name?why it will capture ["wc", "-l"] ?
argv suppose to capture the output from the command before I make command right?