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 - C Tutorial
From the course: C Programming Basics: Flow Control, Variables, and Pointers
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…
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
-
-
-
-
-
-
Manipulating single characters4m 50s
-
(Locked)
Using logical operators4m 8s
-
(Locked)
Manipulating strings5m 29s
-
(Locked)
Challenge: Build a string44s
-
(Locked)
Solution: Build a string2m 15s
-
(Locked)
Exploring constant expressions4m 36s
-
(Locked)
Understanding arrays5m 59s
-
(Locked)
Creating multidimensional arrays4m 10s
-
(Locked)
Challenge: Add a dimension to an array28s
-
(Locked)
Solution: Add a dimension to an array1m 24s
-
(Locked)
Understanding structures5m 54s
-
-
-