A
arnuld
this is an example programme that counts lines, words and characters.
i have noticed one thing that this programme counts space, a newline
and a tab as a character.
i know:
1. a newline is represented as '\n'
2. a tab as '\t'
3. a space as ' '
what i want to know is whether a newline, a space and a tab are
represented internally as characters ?
i know everything is represented as machine's character set, most
probably ASCII where 'A' is 65 but i am actually confused on this
'\t', '\n' , ' ', and character issue.
any help
here is the code that counts characters,words,tabs and newlines:
// word counting
#include <stdio.h>
#define IN 0
#define OUT 1
int main(void) {
int c, nl, nw, nc, state;
state = OUT;
nl = nc = nw = 0;
while((c = getchar()) != EOF)
{
++nc;
if (c == '\n')
++nl;
if( c == ' ' || c == '\n' || c == '\t')
state = OUT;
else if (state == OUT)
{
state = IN;
++ nw;
}
}
printf("%d NEWLINES \t %d WORDS \t %d CHARs \n", nl, nw, nc);
return 0;
}
i have noticed one thing that this programme counts space, a newline
and a tab as a character.
i know:
1. a newline is represented as '\n'
2. a tab as '\t'
3. a space as ' '
what i want to know is whether a newline, a space and a tab are
represented internally as characters ?
i know everything is represented as machine's character set, most
probably ASCII where 'A' is 65 but i am actually confused on this
'\t', '\n' , ' ', and character issue.
any help
here is the code that counts characters,words,tabs and newlines:
// word counting
#include <stdio.h>
#define IN 0
#define OUT 1
int main(void) {
int c, nl, nw, nc, state;
state = OUT;
nl = nc = nw = 0;
while((c = getchar()) != EOF)
{
++nc;
if (c == '\n')
++nl;
if( c == ' ' || c == '\n' || c == '\t')
state = OUT;
else if (state == OUT)
{
state = IN;
++ nw;
}
}
printf("%d NEWLINES \t %d WORDS \t %d CHARs \n", nl, nw, nc);
return 0;
}