From the course: Complete Guide to C Programming Foundations
Chapter challenge: Processing input - C Tutorial
From the course: Complete Guide to C Programming Foundations
Chapter challenge: Processing input
(bright music) - [Instructor] Here's the code skeleton for this chapter's challenge, where your task is to write a function that processes input. The main function calls the get input function twice. Its argument is the number of characters to process, which includes the null character. The return value is a string, the text input. The function does two useful things, it allocates storage for input based on the size desired, and it ensures that the string input doesn't terminate with a new line character. Your task is to write the get_input function. It must allocate storage based on the value passed. If storage cannot be allocated, the program quits. Once storage is allocated the function reads standard input. The input is stored in the freshly allocated buffer. Ensure that text input is scanned, and if the new line is found, it's removed, replaced with a null character. The function returns the modified string. For hints, remember that this chapter is all about pointers. Yes, you must allocate storage in the get_input function, but I also want you to use pointer notation as you manipulate the text input. Remember to free the allocated memory when the program quits. This challenge should take you about 10 minutes to complete.
Contents
-
-
-
-
-
-
-
-
-
-
Understanding pointers3m 23s
-
(Locked)
Using pointers to manipulate data2m 53s
-
(Locked)
Doing pointer math3m 10s
-
(Locked)
Comparing arrays and pointers5m 5s
-
(Locked)
Challenge: Output a string57s
-
(Locked)
Solution: Output a string2m 44s
-
(Locked)
Allocating storage3m 42s
-
(Locked)
Working with a pointer array4m
-
(Locked)
Using pointers in structures3m 8s
-
(Locked)
Challenge: Allocating structures1m 3s
-
(Locked)
Solution: Allocating structures3m 34s
-
(Locked)
Passing pointers to functions2m 23s
-
(Locked)
Returning pointers from a function2m 31s
-
Chapter challenge: Processing input1m 26s
-
(Locked)
Chapter solution: Processing input3m 14s
-
-
-
-