Skip to content

Commit 3eb1df2

Browse files
author
Joshua Goller
committed
5.6 const / static
1 parent 8c8247e commit 3eb1df2

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

ch-5/src/5.6.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
#include <string.h>
44
#include <tests.h>
55

6+
/*
7+
Ex. 5.6: Rewrite appropriate programs from earlier chapters and exercises with
8+
pointers instead of array indexing. Good possibilities include getline (Chapters
9+
1 and 4), atoi, itoa, and their variants (Chapters 2, 3, and 4), reverse
10+
(Chapter 3), and strindex and getop (Chapter 4).
11+
*/
12+
613
static void reverse_p(char* const str, const int len) {
714
char *first, *last;
815
char temp;
@@ -17,7 +24,7 @@ static void reverse_p(char* const str, const int len) {
1724
static void test(char* const input, const char* const expected,
1825
const char* const message) {
1926
const int len = (int)strlen(input);
20-
char* copy = (char*)malloc((unsigned long)len);
27+
char* copy = (char*)malloc((unsigned long)len + 1);
2128
strcpy(copy, input);
2229

2330
reverse_p(copy, len);

0 commit comments

Comments
 (0)