From the course: C: Data Structures, Pointers, and File Systems
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Solution: Create a pointer array - C Tutorial
From the course: C: Data Structures, Pointers, and File Systems
Solution: Create a pointer array
(upbeat music) - [Instructor] Here is my solution to the challenge which is just one way to accomplish the task. Your code need not be identical to what you see here. I named my character pointer array fruit at line seven. It's an array of 10 memory locations that reference character storage. At line eight, the buffer storage space is used for string input. The first for loop at line 11 fetches input, creates buffers, and assigns those buffer addresses to the fruit array elements. First at lines 14 and 15, input is fetched and stored in the buffer array. At line 18 storage is allocated for the fruit array element x, based on the input string's length, plus one for the null character. I hope you didn't forget this plus one part of the allocation. The if statements handle the condition when memory isn't available, otherwise the address of the string input is copied into a element of the fruit array at line 26. This loop repeats for all 10 elements in the fruit array. The second for loop…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Understanding pointers3m 19s
-
(Locked)
Using pointers to manipulate data2m 28s
-
(Locked)
Doing pointer math2m 57s
-
(Locked)
Comparing arrays and pointers3m 55s
-
(Locked)
Allocating storage3m 15s
-
Working with a pointer array3m 38s
-
(Locked)
Using pointers in structures3m 30s
-
(Locked)
Passing pointers to functions2m 57s
-
(Locked)
Returning pointers2m 39s
-
(Locked)
Challenge: Create a pointer array54s
-
(Locked)
Solution: Create a pointer array2m 23s
-
-
-
-