This program reads a file given as command line argument
and outputs all the lines in the file that contain the
sequence of characters WORD. WORD is passed in as command line argument. I added an option to this code where the user can chose to have the line number written out as well. The option is indicated by a command line argument -n. But when i use this option it keeps telling me that am passing a wrong parameter.IS there a reason why it doesnt recognise "-n" as a string?



[code]

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef char * STRNG;

STRNG code[80];
STRNG keep[80];
STRNG get_line(FILE * inf)
{/*Start of the function which reads one line*/
STRNG s = NULL;
int count = 0;
int tok; // must be int - EOF is an int, not a char

while ( (tok=getc(inf)) != EOF && tok != '\n' )
{
if ( s == NULL ) s = malloc( 81 );
s[count++] = tok;
}
if ( tok != EOF )
{
if ( s == NULL ) s = malloc( 81 ); // possibly a newline on its own
s[count++] = tok; // append the \n
s[count] = '\0';
}
return s;
}

int main(int argc, char *argv[])
{
char *filename;
FILE *stream;
int i=0,rest,count=0, n = 0;
char *loc;

char *linenum;
STRNG word =argv[1];
filename =argv[2];
stream=fopen(filename,"r");
if (argc ==4)
{
linenum=argv[1];
word =argv[2];
filename=argv[3];
stream=fopen(filename,"r");

}

if (linenum !="-n")
{printf("Wrong parameter.Try <n>\n");}/*i guess the problem starts here*/

if(word==NULL)
{
printf("Syntax error.Program will exit.\n");
exit(1);
}


if(stream ==NULL)
{
printf("Enter a valid filename.Program will exit.\n");
exit(1);
}
while((code[n]=get_line(stream))!=NULL)
{
n++;
}
i=n;

for (n=0;n<i;n++)
{
count++;
if(strlen(code[n])>80)
{
printf("Error: Line %d is too big\n",++n);
exit(1);
}
loc=strstr(code[n],word);
if(loc!=NULL){
if (argc==3)printf("%s",code[n]);
else
if ((argc==4)&&(linenum=="-n"))/*same problem here*/
{
printf("%d %s", count, code[n]);
}
}

}


return 0; // 0 is success
}