Code:
#include <stdio.h>
int Trim(char* buffer, char* s)
{
int index = 0;
int len = 0;
for(; s[index] != '\0'; index++)
{
if (s[index] != ' ')
{
buffer[len] = s[index];
len++;
}
}
buffer[len] = 0;
// returns the length of buffer:
return len;
}
int main()
{
char buff[256];
char str[] = "| Hello World |";
Trim(buff, str);
printf("Normal string: %s\nSame string, but trimmed: %s\n", str, buff);
system("pause"); // Not portable
return 0;
}
Copy the char array to the buffer only if is not a blank space