#include <stdio.h>
void stripnl(char *str) {
while(strlen(str) && ( (str[strlen(str) - 1] == 13) ||
( str[strlen(str) - 1] == 10 ))) {
str[strlen(str) - 1] = 0;
}
}
int main() {
FILE *infile;
char fname[40];
char line[100];
int lcount;
printf("Enter the name of a ascii file: ");
fgets(fname, sizeof(fname), stdin);
stripnl(fname);
if((infile = fopen(fname, "r")) == NULL) {
printf("Error Opening File.\n");
exit(1);
}
while( fgets(line, sizeof(line), infile) != NULL ) {
lcount++;
printf("Line %d: %s", lcount, line);
}
fclose(infile);
}