C Program to Delete White Spaces from String

C Program to Delete White Spaces from String

Write C Program to Delete White Spaces from String

//C Program to Delete White Spaces from String

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

int main()
{
	char S[50];
	int i = 0;

	printf("Enter String :--> ");
	gets(S);
	int n = strlen(S);

	while(i < n)
        {
	 	if(S[i] == ' ')
	 	{
	 		int j = i;
	 		while(j < n-1)
	 		{
	 			S[j] = S[j + 1];
	 			j++;
			 }
			 n--;
			 i--;
		 }
		 i++;
	 }
	 S[i]='\0';

	printf("\nString After Removal of White Space :--> %s", S);

	return 0;
}

Output:

Enter String :--> Hi, Hello and Welcome to CodeCrucks

String After Removal of White Space :--> Hi,HelloandWelcometoCodeCrucks