When i compile my program only the character counts seems to be returning the proper value, but line and word count return 0 and 1 respectivley. From my previous post I understand that the program didnt see the hard returns, so my question is this:
I typed the gettysburg address in notepad and saved it as a text file on the a:\drive. Is notepad not capable of displayed the 'hard return' or is c unable to read 'hard returns' from note and it is better to use another editor like 'wordpad'?
Here is a copy of my code;
[code]
#include <stdio.h>
#include <conio.h>
#define WHT_SPC (symbol == " " || symbol == '\n' || symbol == '\t')
main()
{
char symbol;
int preSymbol;
int lineCount = 0;
int symbolCount = 0;
int wordCount = 0;
char word = 'O';
FILE *gettyadd;
clrscr();
if (!(gettyadd = fopen("A:\\gettyadd.txt", "r")))
}
printf("Unable to open file for reading");
getch();
return (1);
}
while ((symbol = fgetc(gettyadd)) != EOF)
{
if (symbol != '\n')
symbolCount++;
else
lineCount++;
}
if (preSymbol != '\n')
lineCount++;
while ((symbol = fgetc(gettyadd)) != EOF)
{
if (WHT_SPC)
word = 'O';
else
if (word == 'O')
{
wordCount++;
word = 'I';
}
}
printf("The number of characters is: %d\n", symbolCount);
printf("The number of lines is: %d\n", lineCount);
printf("The number of words is: %d\n", wordCount);
fclose(gettyadd);
getch();
return 0;
}
[\code]
Thanks for your time.