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*/
|
* as opposed to a series of if statements*/
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
int a = 0; /*Initializing a as zero; this doesn't matter because getchar is called at the top of the loop */
|
int a = 0; /*Initialized as 0 becasue getchar is called both on loop entry, and after every successful execution*/
|
||||||
|
|
||||||
while (a != EOF){
|
|
||||||
|
|
||||||
a = getchar();
|
|
||||||
|
|
||||||
|
for (a = 0; a != EOF; a = getchar()){
|
||||||
switch (a){
|
switch (a){
|
||||||
case '\t':
|
case '\t':
|
||||||
printf ("\\t");
|
printf ("\\t");
|
||||||
|
|
@ -20,8 +17,6 @@ int a = 0; /*Initializing a as zero; this doesn't matter because getchar is call
|
||||||
case '\b':
|
case '\b':
|
||||||
printf ("\\b");
|
printf ("\\b");
|
||||||
break;
|
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:
|
default:
|
||||||
putchar (a);
|
putchar (a);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue