I am working my way through "The C Programming Language".
I am on the topic of input/output in the first chapter and at the end of the section we are supposed to write a program that counts the spaces, tabs, and new lines. I wrote the program no problem but i can't get the program to exit and give me the output for number of spaces, tabs, and new lines.
i even tried on of the simpler programs from the book just to make sure it wasn't my logic. it wasn't, i just don't know how to exit the program correctly.
here is what i have for reference (my program):
Code:
#include <stdio.h>
main()
{
int c; /* Counting variable */
int ns = 0; /* Number of spaces */
int nl = 0; /* Number of lines */
int nt = 0; /* Number of tabs */
for ( c = 0; (c = getchar()) != EOF; c++)
{
if( c == '\t')
{
nt++;
}
if( c == '\n')
{
nl++;
}
if( c == ' ')
{
ns++;
}
}
printf("%d\t%d\t%d\n", ns, nt, nl);
}
thanks in advance.