Q:

IS THERE ANY INBUILT LIBRARY FUNCTION IN C TO REMOVE LEADING AND TRAILING SPACES FROM A STRING? HOW WILL YOU REMOVE THEM IN C?

belongs to collection: C INTERVIEW QUESTIONS AND ANSWERS

0

 IS THERE ANY INBUILT LIBRARY FUNCTION IN C TO REMOVE LEADING AND TRAILING SPACES FROM A STRING? HOW WILL YOU REMOVE THEM IN C?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this 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.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C INTERVIEW QUESTIONS AND ANSWERS

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
WHAT IS THE DIFFERENCE BETWEEN STRCPY() & STRNCPY(... >>
<< WHAT IS THE DIFFERENCE BETWEEN MEMCPY() & MEMMOVE(...