aboutsummaryrefslogtreecommitdiff
path: root/ch3
diff options
context:
space:
mode:
authorzlg <zlg@zlg.space>2016-06-16 10:15:33 -0700
committerzlg <zlg@zlg.space>2016-06-16 10:15:33 -0700
commitf8d9ff23eb8d3e3286ff5cf4d5f9493532991bb7 (patch)
treee37b327d7f93435e93a57427600d2b91fbb0cd87 /ch3
parentSolve Exercise 7-2: Format arbitrary input (diff)
downloadknr-f8d9ff23eb8d3e3286ff5cf4d5f9493532991bb7.tar.gz
knr-f8d9ff23eb8d3e3286ff5cf4d5f9493532991bb7.tar.bz2
knr-f8d9ff23eb8d3e3286ff5cf4d5f9493532991bb7.tar.xz
knr-f8d9ff23eb8d3e3286ff5cf4d5f9493532991bb7.zip
The massive astyle sweep!
Code style should be consistent now. All future commits will be run through astyle or they will be amended.
Diffstat (limited to '')
-rw-r--r--ch3/3-01_binsearch2.c4
-rw-r--r--ch3/3-02_escape.c2
-rw-r--r--ch3/3-03_expand.c8
-rw-r--r--ch3/3-04_itoa2.c5
-rw-r--r--ch3/3-05_itob.c5
-rw-r--r--ch3/3-06_itoa3.c6
6 files changed, 5 insertions, 25 deletions
diff --git a/ch3/3-01_binsearch2.c b/ch3/3-01_binsearch2.c
index bcd66c3..6502273 100644
--- a/ch3/3-01_binsearch2.c
+++ b/ch3/3-01_binsearch2.c
@@ -24,7 +24,6 @@
int binsearch(int x, int v[], int n) {
int low, mid, high;
-
low = 0;
high = n - 1;
while (low <= high) {
@@ -42,10 +41,8 @@ int binsearch(int x, int v[], int n) {
int binsearch2(int x, int v[], int n) {
int low, mid, high;
-
low = 0;
high = n - 1;
-
while (low < high) {
mid = (low + high) / 2;
if (x <= v[mid]) {
@@ -54,7 +51,6 @@ int binsearch2(int x, int v[], int n) {
low = mid + 1;
}
}
-
if (x == v[low]) {
return low;
} else {
diff --git a/ch3/3-02_escape.c b/ch3/3-02_escape.c
index 04910ec..25bfa34 100644
--- a/ch3/3-02_escape.c
+++ b/ch3/3-02_escape.c
@@ -17,7 +17,7 @@ void escape(char s[], char t[]) {
int i, j;
j = 0;
for (i = 0; t[i] != '\0'; i++) {
- switch(t[i]) {
+ switch (t[i]) {
case '\n':
s[j++] = '\\';
s[j++] = 'n';
diff --git a/ch3/3-03_expand.c b/ch3/3-03_expand.c
index b0a4011..f00ba6a 100644
--- a/ch3/3-03_expand.c
+++ b/ch3/3-03_expand.c
@@ -56,27 +56,19 @@ int main() {
char woot[21] = "-a-f0-36-9b-h-";
char derp[21] = "a-28-t";
char dest[61] = "";
-
printf("%26s\n", "INPUT | OUTPUT");
printf("%27s\n", "-----------------");
-
expand(foo, dest);
printf("%16s => %s\n", foo, dest);
-
expand(bar, dest);
printf("%16s => %s\n", bar, dest);
-
expand(baz, dest);
printf("%16s => %s\n", baz, dest);
-
expand(fob, dest);
printf("%16s => %s\n", fob, dest);
-
expand(woot, dest);
printf("%16s => %s\n", woot, dest);
-
expand(derp, dest);
printf("%16s => %s\n", derp, dest);
-
return 0;
}
diff --git a/ch3/3-04_itoa2.c b/ch3/3-04_itoa2.c
index 6c2fa2f..099b9de 100644
--- a/ch3/3-04_itoa2.c
+++ b/ch3/3-04_itoa2.c
@@ -21,8 +21,7 @@
void reverse(char s[]) {
int c, i, j;
-
- for (i = 0, j = strlen(s)-1; i < j; i++, j--) {
+ for (i = 0, j = strlen(s) - 1; i < j; i++, j--) {
c = s[i];
s[i] = s[j];
s[j] = c;
@@ -31,7 +30,6 @@ void reverse(char s[]) {
void itoa(int n, char s[]) {
int i, sign, min; // Add 'min' for later use
-
if ((sign = n) < 0) {
/* Detect this and add one so it can properly be made positive */
if (n == INT_MIN) {
@@ -62,7 +60,6 @@ int main() {
int tests[5] = {INT_MIN, INT_MAX, -300, 172, 38478235};
char st[101] = "";
int i;
-
for (i = 0; i < 5; i++) {
itoa(tests[i], st);
printf("%12d in string form is %12s\n", tests[i], st);
diff --git a/ch3/3-05_itob.c b/ch3/3-05_itob.c
index 58066e5..fdb3a15 100644
--- a/ch3/3-05_itob.c
+++ b/ch3/3-05_itob.c
@@ -16,8 +16,7 @@
void reverse(char s[]) {
int c, i, j;
-
- for (i = 0, j = strlen(s)-1; i < j; i++, j--) {
+ for (i = 0, j = strlen(s) - 1; i < j; i++, j--) {
c = s[i];
s[i] = s[j];
s[j] = c;
@@ -26,7 +25,6 @@ void reverse(char s[]) {
void itob(int n, char s[], unsigned b) {
int i, sign, min, rem; // Add 'min' for later use
-
if ((sign = n) < 0) {
/* Detect this and add one so it can properly be made positive */
if (n == INT_MIN) {
@@ -76,7 +74,6 @@ int main() {
int tests[5] = {INT_MIN, INT_MAX, -300, 172, 38478235};
char st[101] = "";
int i;
-
for (i = 0; i < 5; i++) {
itob(tests[i], st, 16);
printf("%12d in string form is %12s\n", tests[i], st);
diff --git a/ch3/3-06_itoa3.c b/ch3/3-06_itoa3.c
index 3c28b0b..da60092 100644
--- a/ch3/3-06_itoa3.c
+++ b/ch3/3-06_itoa3.c
@@ -15,8 +15,7 @@
void reverse(char s[]) {
int c, i, j;
-
- for (i = 0, j = strlen(s)-1; i < j; i++, j--) {
+ for (i = 0, j = strlen(s) - 1; i < j; i++, j--) {
c = s[i];
s[i] = s[j];
s[j] = c;
@@ -25,7 +24,6 @@ void reverse(char s[]) {
void itoa(int n, char s[], unsigned fw) {
int i, sign, min; // Add 'min' for later use
-
if ((sign = n) < 0) {
/* Detect this and add one so it can properly be made positive */
if (n == INT_MIN) {
@@ -58,7 +56,7 @@ void itoa(int n, char s[], unsigned fw) {
int main() {
int i;
char foo[16] = "";
- int tests[5] = {-25, 409689, 8, -1000, 135};
+ int tests[5] = { -25, 409689, 8, -1000, 135};
for (i = 0; i < 5; i++) {
itoa(tests[i], foo, 5);
printf("Pad to 5 spaces! '%s'\n", foo);
amp;id=a90ed3b7086677c04bc4c42fb867d75e1dfd64d6&follow=1'>DerpZe Libertine Gamer1-0/+1 2016-11-03Improve error handling in shell scriptsZe Libertine Gamer4-3/+23 2016-10-24Correct run_again, add recursionZe Libertine Gamer1-0/+4 2016-10-21Add quotes to correct behavior for arglistZe Libertine Gamer1-1/+1 2016-10-14updater.sh: add recursion, error handlingZe Libertine Gamer1-43/+101 2016-10-14Correct pipe-handling behaviorZe Libertine Gamer1-1/+9 2016-10-12Clarify a method to move between platformsZe Libertine Gamer1-2/+5