Implemented suggestions from affine. Considerably simplified the program by removing initialization for 'a' prior to loop entry; 'a' is now declared as the initialization expression for the loop, performing a getchar at the same time and preventing a null byte from being printed as the first character (even though this was not visible to the user).

This commit is contained in:
Reina Harrington-Affine 2025-08-14 20:02:00 +00:00
parent abc0ac1660
commit 635a8300a3

View file

@ -4,9 +4,8 @@
* as opposed to a series of if statements*/ * as opposed to a series of if statements*/
int main(){ int main(){
int a = 0; /*Initialized as 0 becasue getchar is called both on loop entry, and after every successful execution*/
for (a = 0; a != EOF; a = getchar()){ for (int a = getchar(); a != EOF; a = getchar()){
switch (a){ switch (a){
case '\t': case '\t':
printf ("\\t"); printf ("\\t");