Example 74: Common String Functions Implementation
Learn how to implement common string functions.
We'll cover the following...
Problem
Write a program to implement the following functions:
- strlen: Finds the length of the string
- strcpy: Copies contents of one string to another string
- strcat: Appends one string at the end of another string
- strcmp: Compares two strings to find whether they are identical or not
Example
Suppose we have the following four strings:
- s1[] = “kicit”
- s2[] = “Nagpur”
- s3[20] = “”
- s4[] = “kicit”
These strings will be used as inputs for the examples given in the table below.
Function | Input | Output |
---|---|---|
strLen | s1 | 5 |
strCpy | s3, s1 |
Access this course and 1400+ top-rated courses and projects.