A
arnuld
exercise: counts spaces, tabs and newlines in the input
for that, Richard Heathfield has created a C programme at his answers-
page:
http://users.powernet.co.uk/eton/kandr2/krx108.html
i have also created my programme which runs fine. i want to have some
comments on my programme, in comparison with Richard's.
---------------- MY PROGRAMME ---------------------
/* section
1.5.3
exercise
1.8
count the
blanks
*/
#include <stdio.h>
int main(void) {
int blanks = 0;
int tabs = 0;
int newlines = 0;
int c;
while((c=getchar()) != EOF) {
if(c == ' ')
++blanks;
if( c == '\n')
++newlines;
if(c == '\t')
++tabs;
}
printf("%d \t %d\t %d\t \n", blanks, tabs, newlines);
return 0;
}
for that, Richard Heathfield has created a C programme at his answers-
page:
http://users.powernet.co.uk/eton/kandr2/krx108.html
i have also created my programme which runs fine. i want to have some
comments on my programme, in comparison with Richard's.
---------------- MY PROGRAMME ---------------------
/* section
1.5.3
exercise
1.8
count the
blanks
*/
#include <stdio.h>
int main(void) {
int blanks = 0;
int tabs = 0;
int newlines = 0;
int c;
while((c=getchar()) != EOF) {
if(c == ' ')
++blanks;
if( c == '\n')
++newlines;
if(c == '\t')
++tabs;
}
printf("%d \t %d\t %d\t \n", blanks, tabs, newlines);
return 0;
}