Rewrote while loop as a for loop to reduce overall program size.
This commit is contained in:
parent
d6f81778ef
commit
abc0ac1660
1 changed files with 2 additions and 7 deletions
|
|
@ -4,12 +4,9 @@
|
|||
* as opposed to a series of if statements*/
|
||||
|
||||
int main(){
|
||||
int a = 0; /*Initializing a as zero; this doesn't matter because getchar is called at the top of the loop */
|
||||
|
||||
while (a != EOF){
|
||||
|
||||
a = getchar();
|
||||
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()){
|
||||
switch (a){
|
||||
case '\t':
|
||||
printf ("\\t");
|
||||
|
|
@ -20,8 +17,6 @@ int a = 0; /*Initializing a as zero; this doesn't matter because getchar is call
|
|||
case '\b':
|
||||
printf ("\\b");
|
||||
break;
|
||||
case EOF: /*Required case for checking if a is EOF, since the loop actually tests whether a = EOF before refreshing a, thus allowing us to enter the loop with the value of a set to EOF */
|
||||
break;
|
||||
default:
|
||||
putchar (a);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue