Please help!!! using C Language.
I don't know how to do it, something like this..
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#define MAX_LIMIT 512 //max of 512 bytes
int main(int argc, char* argv[]){
int ifp, ofp; //used for input and output
if (argc == 4){
//grep on text_pattern
char *args[MAX_LIMIT] = {"grep", argv[1], NULL};
//open input and output files
ifp = open("in.txt", O_WRONLY | O_APPEND);
ofp = open("out.txt", O_WRONLY | O_APPEND);
//duplicate input file to stdin
dup2(ifp, 0);
//duplicate output file to stdout
dup2(ofp, 1);
//close unused input file descriptor
close(ifp);
//close unused output file descriptor
close(ofp);
//execute grep
execvp("grep", args);
}
else{
printf("usage: %s text_pattern input_file output_file\n", argv[0]);
}
return 0;
}