I'm trying to write a small program in Unix in C to get commands from the command line and then perform them. ie., filename.c dir = ls... But, I can't quite figure out how to move the command from argv[] to the system command. This is what I have so far:
#include %26lt;sys/wait.h%26gt;
#include %26lt;unistd.h%26gt;
#include %26lt;stdio.h%26gt;
#include %26lt;stdlib.h%26gt;
int main(int argc, char *argv[])
{
system = argv[1];
if (argc=2 )
{
if (status="clr")
{
system ("clear");
}
if (status="dir");
{
system ("ls");
}
if (status="environ")
{
system ("environ");
}
}
else (status="quit");
{
system (exit);
}
}
Help with a C program in unix.?
You're comparing strings, not integers.
if( strcmp( argv[1], "dir" ) == 0 ) {
system("ls");
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment