I have a text file with the line:
12/16/2008**10:21*AM***************969*happyclown.html
where *=whitespace. There are 19 whitespaces. I have to use * to show you whitespace, because for some reason, this forum won't allow more than a single whitespace between words or colums. And the tiny little forum compose box makes formatting a nightmare.
So I wrote a program to count the whitespaces.
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *openfile;
int whitespacecount = 0, tabspacecount = 0;
int c;
/* Open file for reading */
if( (openfile = fopen("directorylisting.txt", "rt")) == NULL )
{
perror("\ndirectorylisting.txt");
exit(EXIT_FAILURE);
}
/* Count whitespaces while not EOF, or end of string */
while( (c = getc(openfile) != EOF) && (c = getc(openfile) != '\0'))
{
if (c = ' ')
whitespacecount++;
if (c = '\t') /* try to count columns of whitespace */
tabspacecount++;
}
printf("The number of whitespaces is %d\n", whitespacecount+1);
printf("The number of tabspaces is %d\n", tabspacecount+1);
return 0;
}
But when I run the program, the output is 29, instead of 19 whitespaces. Why?
Thanks.