C_String_Questions_Answers
C_String_Questions_Answers
Answer:
A string in C is an array of characters terminated by a null character ('\0'). It
is used to store a sequence of characters, such as words or sentences.
14. How do you trim spaces from the beginning and end of a string?
Answer:
To trim spaces, you can use a loop to shift the characters:
#include <ctype.h>
int start = 0, end = strlen(str) - 1;
while (isspace(str[start])) start++;
while (isspace(str[end])) end--;
for (int i = start; i <= end; i++) {
printf("%c", str[i]);
}