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 ...
- 02-22-2008 #1Just 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
- 02-22-2008 #2Just Joined!
- Join Date
- Feb 2008
- Posts
- 7
#include <stdlib.h>
int main()
{
system("/bin/ls");
return 0;
}
hope it helps
- 02-25-2008 #3
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!


Reply With Quote
