Everytime I compile, A value of 1 is returned for the total number of lines. I am still very new at C, so I am sure I am overlooking something stupid. Just need a little direction. Thanks in advance for your time.
Here is the code:
#include <stdio.h>
#include <conio.h>
main()
{
char symbol;
int preSymbol;
int lineCount = 0;
int symbolCount = 0;
FILE *gettysburg;
if (!(gettysburg = fopen("A:\\gettysburg.txt", "r")))
{
printf("Unable to open file for reading");
return (1);
}
while ((symbol = fgetc(gettysburg)) != EOF)
{
if (symbol != '\n')
symbolCount++;
else
lineCount++;
preSymbol = symbol;
}
if (preSymbol != '\n')
lineCount++;
printf("The number of characters is: %d\n", symbolCount);
printf("The number of lines is: %d\n", lineCount);
fclose(gettysburg);
getch();
return 0;
}