when I run the first program, nl
(newline) is set to 7ff, and prints out 129.
#include<stdio.h>
// countblanks-tabs-newlinesv1.c
void main()
{
long int c;
unsigned char nl, space, tab = 0 ;
while( ( c = getchar() ) != EOF)
{
if ( c == '\n')
{
nl++;
}
if ( c == ' ')
{
space++;
}
if ( c == '\t')
{
tab++;
}
}
printf("input has %d newlines, %d spaces and %d tabs\n", nl, space, tab);
}
But when I run the second program everything works fine...I think.
Second program
#include<stdio.h>
// countblanks-tabs-newlinesv2.c
void main()
{
long int c;
char space, tab ;
int nl;
nl = 0;
space = 0 ;
tab = 0;
while( ( c = getchar() ) != EOF)
{
if ( c == '\n')
{
nl++;
}
if ( c == ' ')
{
space++;
}
if ( c == '\t')
{
tab++;
}
}
printf("input has %d newlines, %d spaces and %d tabs\n", nl, space, tab);
}
btw this is exercise 1-8 in The C Programming Language Book