I need help about "cat"

I asked by someone to change linux's program "cat"

to change result of "cat A B" to be "cat B A"

http://pastebin.com/VtmXueEq

Can anyone fixed this and pastebin back to me

Best Regards,
First, cat is a system utility. Make a new program, call it meow or something dog is already taken.

Why post the code somewhere else?

You just process the args right to left.
My friend give the challenge on edit the source code to complete task, I gonna "./configure && make" without "make install" to not replace with my original cat


full source code here http://ftp.gnu.org/gnu/coreutils/coreutils-8.19.tar.xz

Bad news...I don't know anything about C++, I'm PHP Programmer T__T
Last edited on
1
2
3
4
5
6
7
8
9
10
11
#include <cstdlib>
#include <string>

int main(int argc, char* argv[])
{
     if (!(argc < 3)) {
        std::string command = "cat ";
        command = command + argv[2]+ " " + argv[1];
        std::system(command.c_str());
    }
}
Works on Linux systems. Probably.
Last edited on
Thanks you so much! but which libraries I have to include?

$ g++ catseen.c
catseen.c: In function ‘int main(int, char**)’:
catseen.c:8:9: error: ‘ctring’ is not a member of ‘std’
catseen.c:8:21: error: expected ‘;’ before ‘command’
catseen.c:9:9: error: ‘command’ was not declared in this scope
catseen.c:10:31: error: ‘system’ was not declared in this scope
catseen.c:11:1: error: expected ‘}’ at end of input
Last edited on
It won't actually do anything. It just calls program "cat" with first two parameters swapped.
I updated my post.
May you forgot one '}' and it's work!! Thanks you again
Topic archived. No new replies allowed.