Problem on Space deleting function

The program below shows a bizarre disfunction. Its target is to delete all empty fields inside a string. I would appreciate any advice about how to make it less complicated too.


#include<stdio.h>
#include<stdlib.h>
#include<string.h>


void DeleteSpace(char A[])
{
int i,j,m,count;

for (i=0;i<strlen(A);i++)
if (A[i]==' ')
{ j=i;
while (j<strlen(A))
{
A[j]=A[j+1];

if (A[j+1]==' ')
{
count=2;
m=j+2;
do
{
if (A[m]==' ')
{count++;
m++;}
else break;

} while (A[m]!='\0');

for (i=j;i<=strlen(A);i++)
A[i]=A[i+count];

}

j++;
}
}
printf("%s\n",A);




}

main()
{
char C[10];
gets(C);
DeleteSpace(C);
system("pause");

}
Last edited on
the problem occurs when you detect a second space. Don't do any special thing then just prevent i from being increased.

Oh, and:

Please use code tags: [code]Your code[/code]
See: http://www.cplusplus.com/articles/z13hAqkS/
Last edited on
Topic archived. No new replies allowed.