Write a C program to trim both leading and trailing white space characters in a string using loop. How to remove both leading and trailing white space characters in a string using loop in C programming. Logic to delete all leading and trailing white space characters from a given string in C.
Example
Input
Input string: " Lots of leading and trailing spaces. "
Output
String after removing leading and trailing white spaces: "Lots of leading and trailing spaces."
Required knowledge
Basic C programming, Loop, String, Function
Must know – Program to remove element from array
Logic to remove leading and trailing white spaces
In my previous posts, I already explained how to remove leading as well as trailing white space characters from a given string. Here in this program we will combine the logic of both in a single program.
Read more –
Program to trim leading and trailing white spaces
Output
Enter any string: Lots of white spaces. String before trimming white space: ' Lots of white spaces. ' String after trimming white space: 'Lots of white spaces.'
Happy coding
Recommended posts
- String programming exercises index.
- C program to remove extra blank spaces from a string.
- C program to search all occurrences of a character in a string.
- C program to search all occurrences of a word in a string.
- C program to count frequency of each character in a string.
- C program to remove all occurrences of a character from a string.
- C program to remove all repeated characters from a string.