A
arnuld
as i said, i have restarted the book because i overlooked some
material. i want to have some comments/views on this solution. it runs
fine, BTW.
------------------ PROGRAMME --------------
/* K&R2 section 1.5.3, exercise 1-8
write a programme to count blanks, tabs and newlines
*/
#include <stdio.h>
int main()
{
int c;
int ns = 0; /* number of SPACES */
int nt = 0; /* number of TABS */
int nn = 0; /* number of NEWLINES */
while((c = getchar()) != EOF)
{
if(c == ' ')
++ns;
if(c == '\t')
++nt;
if(c == '\n')
++nn;
}
printf("SPACES: %d\nTABS: %d\nNEWLINES: %d\n", ns, nt, nn);
return 0;
}
---------- OUTPUT ----------
[arch@voodo kr2]$ gcc -std=c99 -pedantic -Wall -Wextra ex_1-8.c
[arch@voodo kr2]$ ./a.out
like
SPACES: 0
TABS: 0
NEWLINES: 1
[arch@voodo kr2]$ ./a.out
like this
and this this this
SPACES: 2
TABS: 2
NEWLINES: 2
[arch@voodo kr2]$
material. i want to have some comments/views on this solution. it runs
fine, BTW.
------------------ PROGRAMME --------------
/* K&R2 section 1.5.3, exercise 1-8
write a programme to count blanks, tabs and newlines
*/
#include <stdio.h>
int main()
{
int c;
int ns = 0; /* number of SPACES */
int nt = 0; /* number of TABS */
int nn = 0; /* number of NEWLINES */
while((c = getchar()) != EOF)
{
if(c == ' ')
++ns;
if(c == '\t')
++nt;
if(c == '\n')
++nn;
}
printf("SPACES: %d\nTABS: %d\nNEWLINES: %d\n", ns, nt, nn);
return 0;
}
---------- OUTPUT ----------
[arch@voodo kr2]$ gcc -std=c99 -pedantic -Wall -Wextra ex_1-8.c
[arch@voodo kr2]$ ./a.out
like
SPACES: 0
TABS: 0
NEWLINES: 1
[arch@voodo kr2]$ ./a.out
like this
and this this this
SPACES: 2
TABS: 2
NEWLINES: 2
[arch@voodo kr2]$