Search⌘ K
AI Features

Example 74: Common String Functions Implementation

Explore how to implement common string functions in C such as strlen to find string length, strcpy to copy strings, strcat to concatenate strings, and strcmp to compare strings. This lesson helps you understand and write these fundamental string manipulation routines using pointers and character arrays.

Problem

Write a program to implement the following functions:

  1. strlen: Finds the length of the string
  2. strcpy: Copies contents of one string to another string
  3. strcat: Appends one string at the end of another string
  4. 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 kicit
strCat s3, s2
...