Added comments to explain certain code behaviors in ex1_10.c so that they can be read and referred to later more easily. Future code should be properly annotated on initial commit.
This commit is contained in:
parent
1ac53c22b2
commit
d3262419a8
1 changed files with 3 additions and 3 deletions
|
|
@ -1,13 +1,13 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
int a = 0;
|
int a = 0; /*Initializing a as zero; this doesn't matter because getchar is called at the top of the loop */
|
||||||
|
|
||||||
while (a != EOF){
|
while (a != EOF){
|
||||||
|
|
||||||
a = getchar();
|
a = getchar();
|
||||||
|
|
||||||
if (a == '\b' || a == '\t' || a == '\\'){
|
if (a == '\b' || a == '\t' || a == '\\'){ /*Test whether the currently selected character is a tab, backspace, or backslash */
|
||||||
if (a == '\b'){
|
if (a == '\b'){
|
||||||
printf("\\b");
|
printf("\\b");
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -15,7 +15,7 @@ int a = 0;
|
||||||
if (a == '\t'){
|
if (a == '\t'){
|
||||||
printf("\\t");
|
printf("\\t");
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else { /*There are only three possible cases here, and by the time we get here, we've tested two, hence an else statement is more efficient than doing another entire if statement*/
|
||||||
printf("\\\\");
|
printf("\\\\");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue