Skip to content

Commit f5d8768

Browse files
committed
changed loop to use for instead of while. this is a poor idea
1 parent 48bf486 commit f5d8768

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

Ch1_Tutorial_Introduction/countchar.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
// count characters in input
44
int main(){
5-
long nc = 0; //store the character count as a long int, init it as 0
5+
double nc; //store the character count as a double
66

7-
while (getchar() != EOF) // while the user hasn't entered an EOF
8-
{
9-
++nc; // increment the character count
10-
}
11-
printf("%ld\n",nc); // %ld tells printf we are printing a long int
7+
for (nc = 0; getchar != EOF; ++nc) //weird for loop that kinda goes forever?
8+
; //do nothing within the loop
9+
//isolated semicolon to indicate nothing
10+
printf("%.0f\n", nc);
1211
}

0 commit comments

Comments
 (0)