Ok I changed it a bit, but now I'm having trouble getting the file name into the system call... here's what I did:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main (int argc, char *argv[])
{
int pid, fd;
char command;
/*attempt to get the file name stored in *argv to append to the sort command*/
command = strcat("Sort ",argv[1]);
/*create new process or quit */
if ( (pid = fork() ) == -1 ) {
perror("fork");
exit(1);
}
/*child does the work */
if (pid == 0) {
close(1);
fd = creat("userlist", 0644);
system(command);
perror("System");
exit(1);
}
/*parent waits then reports */
if(pid != 0) {
wait(NULL);
printf("Done running sort. Results in userlist\n");
}
}