Posted By:
23 Jun, 2013 1:16 pm PDT

Strings ( removing spaces ) in C

How can you remove excess spaces in a string?
Attachment:None


This program is used to excess spaces in a string. We use the following logic to remove the excess space :

 

#include <stdio.h>
#include <conio.h> 
int main()
{
   char text[100], blank[100];
   int c = 0, d = 0;
 
   printf("Enter some text\n");
   gets(text);
 
   while (text[c] != '\0')
   {
      if (!(text[c] == ' ' && text[c+1] == ' ')) {
        blank[d] = text[c];
        d++;
      }
      c++;
   }
 
   blank[d] = '\0';
 
   printf("Text after removing blanks\n%s\n", blank);
 
   getch();
}

 

Please see the video for more details.

Was it useful?  




Please login to reply to this problem.



Related Problems on Fixoncloud