c program remove spaces, blanks from a string
C code to remove spaces or excess blanks from a string, For example consider the string
there are two spaces in this string, so our program will print a string "c programming". It will remove spaces when they occur more than one time consecutively in string anywhere.
#include<stdio.h>
#include<string.h>
#include<malloc.h>
#define SPACE ' '
main()
{
char string[100], *blank, *start, *end;
int length;
printf("Enter a string\n");
gets(string);
length = strlen(string);
blank = string;
end = start = (char*)malloc(length+1);
while(*blank)
{
if ( *blank == SPACE && *(blank+1) == SPACE )
{}
else
{
*start = *blank;
start++;
}
blank++;
}
*start='\0';
start = end;
printf("%s", start);
return 0;
}