Search⌘ K

Example 75: Extract a Substring

Explore how to extract substrings from strings in C by using specialized functions that handle left, right, or middle extraction. Understand how to manage substring positions and lengths, handle invalid inputs, and create new strings without altering the original. This lesson prepares you to manipulate strings confidently in your C programs.

Problem

Write a program that extracts a substring from the left, right, or middle of a string.

Example

The following string has been used for the examples given in the table.

String: Four hundred and thirty two

Input Output
getsub (str, 5, 7) hundred
leftsub (str, 4) Four
rightsub (str, 3) two

Try it yourself - getsub

...