C code to remove spaces from a string | LeetCode
Write a C function to remove spaces from a string. The function header should be
void removeSpaces(char *str)
ie, “abc de” -> “abcde”
Read full article from C code to remove spaces from a string | LeetCode
Write a C function to remove spaces from a string. The function header should be
void removeSpaces(char *str)
ie, “abc de” -> “abcde”
void removeSpace(char *str) {
char *p1 = str, *p2 = str;
do
while (*p2 == ' ')
p2++;
while (*p1++ = *p2++);
}
http://www.geeksforgeeks.org/remove-spaces-from-a-given-string/void
removeSpaces(
char
*str)
{
// To keep track of non-space character count
int
count = 0;
// Traverse the given string. If current character
// is not space, then place it at index 'count++'
for
(
int
i = 0; str[i]; i++)
if
(str[i] !=
' '
) // maybe not write if count==i, just count++
str[count++] = str[i];
// here count is
// incremented
str[count] =
'\0'
;
}