#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "mygrep.h"
void main(int argc, char *argv[]) {
check_opts_number(argc, argv);
int iflag = 0;
char *ofile = NULL;
char *keyword = NULL;
char *filename = NULL;
int c;
while((c = getopt(argc, argv, "io:h")) != -1) {
switch(c) {
case 'i':
iflag = 1;
break;
case 'o':
ofile = optarg;
case 'h':
print_usage();
case '?':
exit(EXIT_FAILURE);
default:
abort();
}
if(argv[optind] == NULL) {
printf("Mandatory argument 'keyword' missing.\n");
} else {
keyword = argv[optind];
filename = argv[optind + 1];
if(filename == NULL) {
check_for_string("test", keyword);
exit(EXIT_SUCCESS);
void print_usage() {
printf("mygrep [-i] [-o outfile] keyword [file...]\n");
void check_opts_number(int argc, char *argv[]) {
if(argc <= 1) {
fprintf(stderr, "At least one argument expected.\n");
} else if(argc > 6) {
fprintf(stderr, "Too many arguments supplied.\n");
void check_for_string(char *to_check, char *to_find) {
printf("Not implemented. This function will search for the substring %s in the string %s.\n", to_find, to_check);