From f8d9ff23eb8d3e3286ff5cf4d5f9493532991bb7 Mon Sep 17 00:00:00 2001 From: zlg Date: Thu, 16 Jun 2016 10:15:33 -0700 Subject: The massive astyle sweep! Code style should be consistent now. All future commits will be run through astyle or they will be amended. --- ch4/4-01_strrindex.c | 6 +----- ch4/4-02_atof2.c | 3 --- ch4/4-03_calc-modulus.c | 2 -- ch4/4-04_top-swap.c | 3 --- ch4/4-05_math-funcs.c | 3 --- ch4/4-06_var-support.c | 3 --- ch4/4-07_ungets.c | 3 --- ch4/4-08_one-char.c | 3 --- ch4/4-09_pushed-eof.c | 3 --- ch4/4-10_getline-calc.c | 4 ---- ch4/4-11_getop-v2.c | 3 --- ch4/4-12_recursive-itoa.c | 7 +------ ch4/4-13_recursive-reverse.c | 2 -- ch4/4-14_swap-macro.c | 1 - 14 files changed, 2 insertions(+), 44 deletions(-) (limited to 'ch4') diff --git a/ch4/4-01_strrindex.c b/ch4/4-01_strrindex.c index b6400c4..7818743 100644 --- a/ch4/4-01_strrindex.c +++ b/ch4/4-01_strrindex.c @@ -30,8 +30,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; @@ -40,7 +39,6 @@ void reverse(char s[]) { int strindex(char s[], char t[]) { int i, j, k; - for (i = 0; s[i] != '\0'; i++) { for (j = i, k = 0; t[k] != '\0' && s[j] == t[k]; j++, k++) { } @@ -63,7 +61,6 @@ int strrindex(char s[], char t[]) { int o = strindex(s, t) + strlen(t); reverse(s); reverse(t); - // Be sure to return the correct offset with some math :3 return (strlen(s) - o); } @@ -73,7 +70,6 @@ int main() { char needle[MAXLINE] = "ned"; int pos = strrindex(haystack, needle); int i = 0; - /* This is mostly just to provide a handy visual aid */ printf("The phrase %s's rightmost occurrence is %d:\n", needle, pos); printf("%s\n", haystack); diff --git a/ch4/4-02_atof2.c b/ch4/4-02_atof2.c index 69c42fc..a70e881 100644 --- a/ch4/4-02_atof2.c +++ b/ch4/4-02_atof2.c @@ -19,13 +19,10 @@ double atof(char s[]) { double val, power; int i, sign, esign, exp; - /* Skip whitespace */ for (i = 0; isspace(s[i]); i++) { } - sign = (s[i] == '-') ? -1 : 1; - if (s[i] == '+' || s[i] == '-') { i++; } diff --git a/ch4/4-03_calc-modulus.c b/ch4/4-03_calc-modulus.c index 05d5c1b..e4cfb9d 100644 --- a/ch4/4-03_calc-modulus.c +++ b/ch4/4-03_calc-modulus.c @@ -46,7 +46,6 @@ int main() { int type; double op2; char s[MAXOP]; - while ((type = getop(s)) != EOF) { switch (type) { case NUMBER: @@ -109,7 +108,6 @@ double pop(void) { int getop(char s[]) { int i, c; - while ((s[0] = c = getch()) == ' ' || c == '\t') { } s[1] = '\0'; diff --git a/ch4/4-04_top-swap.c b/ch4/4-04_top-swap.c index 2f884d4..5c60e3b 100644 --- a/ch4/4-04_top-swap.c +++ b/ch4/4-04_top-swap.c @@ -48,7 +48,6 @@ int main() { int type; double op2; char s[MAXOP]; - while ((type = getop(s)) != EOF) { switch (type) { case NUMBER: @@ -128,7 +127,6 @@ double pop(void) { int getop(char s[]) { int i = 0; int c, next; - while ((s[0] = c = getch()) == ' ' || c == '\t') { } s[1] = '\0'; @@ -147,7 +145,6 @@ int getop(char s[]) { } else { c = getch(); } - while (isdigit(s[++i] = c)) { c = getch(); } diff --git a/ch4/4-05_math-funcs.c b/ch4/4-05_math-funcs.c index 6c22767..45c350b 100644 --- a/ch4/4-05_math-funcs.c +++ b/ch4/4-05_math-funcs.c @@ -48,7 +48,6 @@ int main() { int type; double op2; char s[MAXOP]; - while ((type = getop(s)) != EOF) { switch (type) { case NUMBER: @@ -143,7 +142,6 @@ double pop(void) { int getop(char s[]) { int i = 0; int c, next; - while ((s[0] = c = getch()) == ' ' || c == '\t') { } s[1] = '\0'; @@ -162,7 +160,6 @@ int getop(char s[]) { } else { c = getch(); } - while (isdigit(s[++i] = c)) { c = getch(); } diff --git a/ch4/4-06_var-support.c b/ch4/4-06_var-support.c index 02b1d09..5df257a 100644 --- a/ch4/4-06_var-support.c +++ b/ch4/4-06_var-support.c @@ -59,7 +59,6 @@ int main() { double op2; char s[MAXOP]; char ltr; - while ((type = getop(s)) != EOF) { if (isalpha(type) && islower(type)) { push(fetch_var(type)); @@ -180,7 +179,6 @@ double pop(void) { int getop(char s[]) { int i = 0; int c, next; - while ((s[0] = c = getch()) == ' ' || c == '\t') { } s[1] = '\0'; @@ -202,7 +200,6 @@ int getop(char s[]) { } else { c = getch(); } - while (isdigit(s[++i] = c)) { c = getch(); } diff --git a/ch4/4-07_ungets.c b/ch4/4-07_ungets.c index 63a7d7f..61e933b 100644 --- a/ch4/4-07_ungets.c +++ b/ch4/4-07_ungets.c @@ -54,7 +54,6 @@ int main() { double op2; char s[MAXOP]; char ltr; - while ((type = getop(s)) != EOF) { if (isalpha(type) && islower(type)) { push(fetch_var(type)); @@ -175,7 +174,6 @@ double pop(void) { int getop(char s[]) { int i = 0; int c, next; - while ((s[0] = c = getch()) == ' ' || c == '\t') { } s[1] = '\0'; @@ -197,7 +195,6 @@ int getop(char s[]) { } else { c = getch(); } - while (isdigit(s[++i] = c)) { c = getch(); } diff --git a/ch4/4-08_one-char.c b/ch4/4-08_one-char.c index 8080453..6a031b5 100644 --- a/ch4/4-08_one-char.c +++ b/ch4/4-08_one-char.c @@ -53,7 +53,6 @@ int main() { double op2; char s[MAXOP]; char ltr; - while ((type = getop(s)) != EOF) { if (isalpha(type) && islower(type)) { push(fetch_var(type)); @@ -174,7 +173,6 @@ double pop(void) { int getop(char s[]) { int i = 0; int c, next; - while ((s[0] = c = getch()) == ' ' || c == '\t') { } s[1] = '\0'; @@ -196,7 +194,6 @@ int getop(char s[]) { } else { c = getch(); } - while (isdigit(s[++i] = c)) { c = getch(); } diff --git a/ch4/4-09_pushed-eof.c b/ch4/4-09_pushed-eof.c index f130992..53a1af4 100644 --- a/ch4/4-09_pushed-eof.c +++ b/ch4/4-09_pushed-eof.c @@ -53,7 +53,6 @@ int main() { double op2; char s[MAXOP]; char ltr; - ungetch(EOF); while ((type = getop(s)) != EOF) { if (isalpha(type) && islower(type)) { @@ -175,7 +174,6 @@ double pop(void) { int getop(char s[]) { int i = 0; int c, next; - while ((s[0] = c = getch()) == ' ' || c == '\t') { } s[1] = '\0'; @@ -197,7 +195,6 @@ int getop(char s[]) { } else { c = getch(); } - while (isdigit(s[++i] = c)) { c = getch(); } diff --git a/ch4/4-10_getline-calc.c b/ch4/4-10_getline-calc.c index 499e71a..a801f0c 100644 --- a/ch4/4-10_getline-calc.c +++ b/ch4/4-10_getline-calc.c @@ -63,7 +63,6 @@ int main() { double op2; char s[MAXOP]; char ltr; - while (mygetline(buf, BUFSIZE) != 0) { bufp = 0; while ((type = getop(s)) != '\0') { @@ -188,7 +187,6 @@ double pop(void) { int getop(char s[]) { int i, c; - while ((s[0] = c = buf[bufp++]) == ' ' || c == '\t'); if (c >= 'a' && c <= 'z') { return c; @@ -210,7 +208,6 @@ int getop(char s[]) { } else { s[i] = c; } - if (isdigit(c)) { while (isdigit(s[++i] = c = buf[bufp++])); } @@ -264,7 +261,6 @@ double fetch_last(void) { int mygetline(char s[], int lim) { int c, i = 0; - while (--lim > 0 && (c = getchar()) != EOF && c != '\n') { s[i++] = c; } diff --git a/ch4/4-11_getop-v2.c b/ch4/4-11_getop-v2.c index 6c2349b..dca0dbb 100644 --- a/ch4/4-11_getop-v2.c +++ b/ch4/4-11_getop-v2.c @@ -51,7 +51,6 @@ int main() { double op2; char s[MAXOP]; char ltr; - while ((type = getop(s)) != EOF) { if (isalpha(type) && islower(type)) { push(fetch_var(type)); @@ -173,7 +172,6 @@ int getop(char s[]) { int i = 0; int c, next; static int buf = EOF; - if (buf != EOF && buf != ' ' && buf != '\t' && !isdigit(buf) && buf != '.' && (buf < 'a' || buf > 'z')) { c = buf; buf = EOF; @@ -205,7 +203,6 @@ int getop(char s[]) { } else { c = getch(); } - while (isdigit(s[++i] = c)) { c = getch(); } diff --git a/ch4/4-12_recursive-itoa.c b/ch4/4-12_recursive-itoa.c index f2ebdcf..1a6afc4 100644 --- a/ch4/4-12_recursive-itoa.c +++ b/ch4/4-12_recursive-itoa.c @@ -25,24 +25,20 @@ void reverse(char[]); int main(void) { char foo[40] = ""; - itoa(829048, foo); printf("%s\n", foo); itoa(-4021, foo); printf("%s\n", foo); - return 0; } void itoa(int num, char target[]) { static int i = 0; static int neg = 0; - if (num < 0) { neg = 1; num = -num; } - if (num /= 10 > 0) { target[i++] = (num % 10) + '0'; num /= 10; @@ -63,8 +59,7 @@ void itoa(int num, char target[]) { 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; diff --git a/ch4/4-13_recursive-reverse.c b/ch4/4-13_recursive-reverse.c index 85a5b91..6fffad3 100644 --- a/ch4/4-13_recursive-reverse.c +++ b/ch4/4-13_recursive-reverse.c @@ -29,11 +29,9 @@ void reverse(char s[]) { static int i = 0; static int j = 0; int c; - if (j == 0) { j = strlen(s) - 1; } - if (i < j) { c = s[i]; s[i] = s[j]; diff --git a/ch4/4-14_swap-macro.c b/ch4/4-14_swap-macro.c index ac2f102..7e794d4 100644 --- a/ch4/4-14_swap-macro.c +++ b/ch4/4-14_swap-macro.c @@ -22,7 +22,6 @@ int main() { int a = 3; int b = 7; - printf("a is %d, b is %d\n", a, b); swap(int, a, b); printf("Now swap, and... a is %d and b is %d!\n", a, b); -- cgit v1.2.3-54-g00ecf