From the course: C Programming Basics: Flow Control, Variables, and Pointers

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Solution: Build a string

Solution: Build a string

(upbeat music) - [Instructor] Here is my solution, which involves using three buffers. You must have a final buffer in which to store the two combined strings. And here, you see it as fullname, listed at line six, which is twice as large as the other two buffers, firstname and lastname. The other two buffers hold 32 characters each. And always ensure that when combining strings, the final buffer can fit in everything. Input is gathered starting at line 11. The input limit for the fgets function is the same size as the buffer. Firstname is 32. Input firstname, size 32. And standard input is the input source. This is repeated for the last name here and here. The string copy function at line 17. Copies the input firstname into the fullname buffer. And remember, you have to include the string.h header file in order to keep the compiler happy about using these string copy function. The string cat function appends the…

Contents