I am trying to implement a duplicate cat function in c. I am getting segmentation faults, and I am unable to find why.
#include <stdio.h>
#include <stdlib.h>
int main(int argc,char *argv[])
{
char* s; /* input string */
int c;
if(argc==1){
while (gets(s)){
puts(s);
}
}
else{
FILE *file = fopen( "./argv[1]", "r" );
while((c=fgetc(file))!=EOF){
fputc(c,stdout);
}
fclose(file);
}
return 0;
}