I'm learning C and can someone tell me if I'm doing file input right?
I know file and user input can be insecure because of buffer overflows.
#include<stdio.h>
int main(int argc,char *argv[])
{
FILE *file;
char c;
int lines = 1;
if(argc == 2)
{
file = fopen(argv[1],"r");
if(file != NULL)
{
do
{
c = fgetc(file);
if(c == '\n')
{
lines ++;
}
}
while(c != EOF);
printf("%s has %d lines\n",argv[1],lines);
return 0;
}
else
{
puts("Can't open file");
return 1;
}
}
else
{
puts("Only enter one file name");
return 1;
}
}