Find the answer to your Linux question:
Results 1 to 3 of 3
Hi, I am new to Linux world.I know the basic commands in Unix.and I want to develop a c program using Unix command .plz send me the example program thanks ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Feb 2008
    Posts
    18

    How to use unix command in c program


    Hi,
    I am new to Linux world.I know the basic commands in Unix.and I want to develop a c program using Unix command .plz send me the example program

    thanks to all.
    vivek

  2. #2
    Just Joined!
    Join Date
    Feb 2008
    Posts
    7
    #include <stdlib.h>
    int main()
    {
    system("/bin/ls");
    return 0;
    }

    hope it helps

  3. #3
    Just Joined! brahan_7's Avatar
    Join Date
    Dec 2007
    Location
    Deep South
    Posts
    26
    int main(int argc, char *argv[])
    {
    char* userId;
    char buffer[10];

    if(argc != 2) {
    cout << "usage: " << argv[0] << " cmd line arg.\n";
    exit(0);

    }
    userId = argv[1];
    sprintf (buffer, "findName.sh %s", userId);
    system(buffer);

    return 0;

    }

    This program finds the full name that matches a userId entered as a cmd line arg...
    All you need to worry about is the sprintf and system parts and use them as an example.

    This basically works by alowing you to represent your commands as text and them use a system call to run them the system call goes out like anyother function and will return back to the where it left off just like anyother function.

    Also check out these websites:
    http://www.cplusplus.com/reference/c...o/sprintf.html
    http://www.cplusplus.com/reference/c...ib/system.html

    Post anymore questions!

  4. $spacer_open
    $spacer_close

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •