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

Solution: Create a pointer array - C Tutorial

From the course: C: Data Structures, Pointers, and File Systems

Start my 1-month free trial

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…

Contents