Write a program that reads a string and removes emtpy spaces.

Use function gets to read the string.


Difficulty level
This exercise is mostly suitable for students
#include <stdio.h>
#include <string.h>
#define SIZE 100

void main(void)
{
	char str[SIZE];
	int i, j;
	
	printf("Enter a string: ");
	gets(str); 

	i=j=0;
	while(str[i]!='\0')
	{
		if(str[i]!=' ')
			str[j++]=str[i];
		i++;
	}
	str[j]='\0';
	printf("\nString without spaces: %s\n",str);
}


Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Moving all the entries from a Queue onto a Stack