This video provides a brief description and example of strcpy(), strncpy(), strcat(), and strncat().
- [Instructor] String.h provides two very useful functions for copying a string from one location to another. The first one is called strycpy and it receives the destination string and the source string as parameters. It copies character after character in source into destination until the null termination character is found. You may notice that this is risky because if no null character is found in the allocated space for source, it will keep copying, possibly causing a segmentation fold.
So that's where strncpy comes in. This function copies at most count characters from source to destination. Logically, the destination must have enough space to hold the intended amount of characters in both functions. Just like copying strings, string.h provides string concatenation functions. The first one is called strcat, which appends the source string at the end of the destination string.
Again, this is done character by character until the end of source is found, if ever. So that's why there's strncat, which also specifies the number of characters to append in its count parameter.
- Working with header files
- C constants and types
- Unformatted and formatted input/output
- Accessing files with C functions
- Generating random numbers
- Converting strings
- Sorting and searching for data
- Manipulating strings
- Using mathematical functions
Skill Level Intermediate
1. The C Standard Library
2. Input and Output Library: stdio.h
3. General Purpose: stdlib.h
4. String Functions: string.h
5. Mathematical Functions: math.h
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.