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

C Programming Language >   Function in C Language >   Predefined Functions  

Short Question

553


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.


This Particular section is dedicated to Question & Answer only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.




Join Our telegram group to ask Questions

Click below button to join our groups.