I'm trying to remove all the spaces in the string. For example if the string has two spaces then it will reduce the two spaces to only one space.
The code which I'm trying is given below:
#include<stdio.h>
main()
{
char s[] = "Ahmed is not here";
int i,k,si = 0,n = 0,ln;
ln = strlen(s);
for(i=0;i<ln;i++)
{
n = s[i];
if(n == 32)
{
si++;
if(si>1)
{
s[i] = '-';
si = 0;
}
}
}
puts(s);
}
The problem is: I don't know how to remove that empty space so i'm replacing it with "-". Also, the code will delete the single spaces too. Please somebody correct my code and tell me where I was wrong.