thanks it helped a lot!!

Actually,I have another prob right now...
i am trying to make the command cat <filename> | wc -l
well,there seems to be a problem in the reading of the last line from the buffer
Code:
//implementation of cat <filename> | wc -l
#include <stdio.h>
#include <string.h>
#define size 500
int main(int argc,char * argv[])
{
int pipe1[2];
int childpid;
FILE * fp;
char buffer[size];
int status;
int lines;
if(argc!=2)
{
printf("usage : mycat <file name>\n");
exit(1);
}
pipe(pipe1);
childpid=fork();
if(childpid>0)
{
close(pipe1[0]);
fp=fopen(argv[1],"r");
if(fp==NULL)
{
printf("Cannot open file");
exit(1);
}
while(fgets(buffer,sizeof(buffer),fp)!=NULL)
write(pipe1[1],buffer,strlen(buffer));
fclose(fp);
wait(&status);
close(pipe1[1]);
exit(0);
}
else
{
close(pipe1[1]);
lines=0;
while (read(pipe1[0],buffer,sizeof(buffer)) > 0)
lines++;
printf("%d",lines);
close(pipe1[0]);
exit(0);
}
}
take a look if you can...thx in advance...