aboutsummaryrefslogtreecommitdiff
path: root/ch3
diff options
context:
space:
mode:
Diffstat (limited to 'ch3')
-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);