Is there any inbuilt library function in C to remove leading and trailing spaces from a string? How will you remove them in C?

Short Answer
Views 525

Answer:

  • There is no inbuilt function to remove leading and trailing spaces from a string in C. We need to write our own function to remove them.
  • We need to check first non-space character in given string. Then, we can copy that string from where non space character is found. Then, we can check whether any spaces are available in copied string from the end of the string. If space is found, we can copy ‘\0’ in that space until any character is found. Because, ‘\0’indicates the end of the string. Now, we have removed leading and trailing spaces in a given string.

Related Articles:

This section is dedicated exclusively to Questions & Answers. For an in-depth exploration of C Programming Language, click the links and dive deeper into this subject.

Join Our telegram group to ask Questions

Click below button to join our groups.