Yes, the first thing is use a compiler with lots of warnings, and enable those warnings.
Code:
$ gcc -Wall -Wextra foo.c
foo.c: In function ‘main’:
foo.c:8:11: warning: format not a string literal and no format arguments [-Wformat-security]
scanf(filename);
^
foo.c:10:23: warning: passing argument 1 of ‘fgetc’ from incompatible pointer type [-Wincompatible-pointer-types]
while (ch = fgetc(filename) !=EOF)
^
In file included from foo.c:1:0:
/usr/include/stdio.h:531:12: note: expected ‘FILE * {aka struct _IO_FILE *}’ but argument is of type ‘char *’
extern int fgetc (FILE *__stream);
^
foo.c:10:5: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
while (ch = fgetc(filename) !=EOF)
^
foo.c:12:16: warning: comparison between pointer and integer
if (ch == "\n")
^
foo.c:12:16: warning: comparison with string literal results in unspecified behavior [-Waddress]
foo.c:19:26: warning: passing argument 3 of ‘fgets’ from incompatible pointer type [-Wincompatible-pointer-types]
fgets(line, 100, filename);
^
In file included from foo.c:1:0:
/usr/include/stdio.h:622:14: note: expected ‘FILE * restrict {aka struct _IO_FILE * restrict}’ but argument is of type ‘char *’
extern char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream)
^
foo.c:20:22: warning: format ‘%f’ expects argument of type ‘float *’, but argument 3 has type ‘double’ [-Wformat=]
sscanf(line, "%f %s", doub, rest);
^
foo.c:22:27: warning: passing argument 3 of ‘fgets’ from incompatible pointer type [-Wincompatible-pointer-types]
fgets(line2, 100, filename);
^
In file included from foo.c:1:0:
/usr/include/stdio.h:622:14: note: expected ‘FILE * restrict {aka struct _IO_FILE * restrict}’ but argument is of type ‘char *’
extern char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream)
^
foo.c:23:22: warning: format ‘%f’ expects argument of type ‘float *’, but argument 3 has type ‘double’ [-Wformat=]
sscanf(line, "%f %s", doub2, rest);
^
foo.c:26:26: warning: passing argument 2 of ‘fputs’ from incompatible pointer type [-Wincompatible-pointer-types]
fputs( "\n", filename);
^
In file included from foo.c:1:0:
/usr/include/stdio.h:689:12: note: expected ‘FILE * restrict {aka struct _IO_FILE * restrict}’ but argument is of type ‘char *’
extern int fputs (const char *__restrict __s, FILE *__restrict __stream);
^
foo.c:6:12: warning: variable ‘newfile’ set but not used [-Wunused-but-set-variable]
FILE * newfile;
^
foo.c:19:9: warning: ‘line’ may be used uninitialized in this function [-Wmaybe-uninitialized]
fgets(line, 100, filename);
^
foo.c:20:9: warning: ‘doub’ may be used uninitialized in this function [-Wmaybe-uninitialized]
sscanf(line, "%f %s", doub, rest);
^
foo.c:20:9: warning: ‘rest’ may be used uninitialized in this function [-Wmaybe-uninitialized]
$