I am trying to write a C program which trims any occurrence of white spaces in a string and prints the resultant string.But ain't getting the desired result and I am getting some random symbols as the output. Please help me.
#include<stdio.h>
#include<string.h>
int main()
{
char s[100];char a[100];int i;
printf("enter the string:\n");
gets(s);
int len=strlen(s);
for(i=0;i<len;i++)
{
if(s[i]!=' ')
{
a[i]=s[i];
}
}
for(i=0;i<len;i++)
{
printf("%c",a[i]);
}
}
Input: Hello Hello
Expected Output: HelloHello.
Current Output:Hello◄Hello