diff --git a/KNR Redux/a.out b/KNR Redux/a.out new file mode 100755 index 0000000..f0cde7b Binary files /dev/null and b/KNR Redux/a.out differ diff --git a/KNR Redux/ex1-8.c b/KNR Redux/ex1-8.c new file mode 100644 index 0000000..6bc8f5a --- /dev/null +++ b/KNR Redux/ex1-8.c @@ -0,0 +1,25 @@ +#include +#include + +int main(){ + int c = 0; + int whitespace = 0; + + while((c = getchar()) != EOF) + switch(c){ + case '\n': + ++ whitespace; + break; + case '\t': + ++whitespace; + break; + case ' ': + ++whitespace; + break; + break; + } + + printf("%d %c", whitespace, '\n'); + +exit(0); +} diff --git a/KNR Redux/ex1-9-2.c b/KNR Redux/ex1-9-2.c new file mode 100644 index 0000000..35d6920 --- /dev/null +++ b/KNR Redux/ex1-9-2.c @@ -0,0 +1,22 @@ +#include +#include + +int main(){ + int c = 0; + _Bool lastWS = 0; + + while((c = getchar()) != EOF){ + if(c == '\t' || c == ' '){ + if(lastWS == 0){ + lastWS = 1; + putchar(c); + } + } + else{ + lastWS = 0; + putchar(c); + } + } + putchar('\n'); + exit(0); +} diff --git a/KNR Redux/ex1-9.c b/KNR Redux/ex1-9.c new file mode 100644 index 0000000..fd3aa41 --- /dev/null +++ b/KNR Redux/ex1-9.c @@ -0,0 +1,25 @@ +#include +#include + +int main(){ + int c = 0; + _Bool lastWS = 0; + + while((c = getchar()) != EOF){ + //Check if the current character is a whitespace + if(c == '\t'|| c == ' '){ + if(lastWS == 0){ + //If the last character was not also WS, set lastWS 1 and print + lastWS = 1; + putchar(c); + }//If c is WS and last was WS, statement fails. + } + else{ + //If not WS, set lastWS 0 and print. + lastWS = 0; + putchar(c); + } + } + putchar('\n'); + exit(0); +}