Please help me with this Extra Credit program
Hello friends, it has beena while since I asked any questions on this board. Well I am finishing up my 2nd course in C programming. I am doing quite well in a class, but I am having troubles with this extra credit assignment. It is pretty self explanatory (the code I mean) Professor just gave me this assignment since I asked for it many times :) Bascially if I get do it I will get an 'A' in the class. So please help me, I tried many diffirent things but the best coding I have is below. What am I doing wrong? Please take a look, I really need this 'A' to raise my gpa.
Its a multi file program.
Main.c (the main program)
#include "grep.h"
#include "cat.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void main(int ac, char *av[])
{
if(strcmp("av[1]", "grep")==0)
{
fp=fopen("av[3]", "r");
if(fp!=NULL)
grep(fp,av[2]);
else
printf("Bad file entered\n");
}
else if(strcmp("av[1]", "cat")==0)
{
fp=fopen("av[3]", "r");
if(fp!=NULL)
cat(fp,av[2]);
else
printf("Bad file entered\n");
}
else
{
printf("Bad file entered\n");
exit(1);
}
}
cat.c
#include "cat.h"
#include <stdio.h>
void (FILE *fp)
{
while((c=fgets(fp))!=EOF)
putchar(c);
}
cat.h
#ifndef CAT
#define CAT
void cat(FILE *fp); //prototype
#endif
grep.c
#include "grep.h"
#include <stdio.h>
main (int ac, char *av[])
{
char s[1000];
FILE *fp;
for (i=2;i<ac;i++)
fp=fopen(av[i],"r");
if(fp==NULL)
printf("%s is not Found\n",av[i]);
else
{
while(fgets(s,1000,fp) != NULL)
if(strstr(s,av[1])!=NULL)
printf("%s: %s", av[i], s);
} //ends else
fclose(fp);
} //ends for loop
} //ends main
grep.h
#ifndef GREP
#define GREP
void grep(FILE *fp); //prototype
#endif:D :D :confused: