C program to print string by eliminating extra white spaces

#include <stdio.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);

   return 0;
}


Output:



Enter some text                                                                                                                                
My                     name is            bond ,    James     bond                                                                 
Text after removing blanks                                                                                                                     
My name is bond , James bond

Comments

Popular posts from this blog

C program to print the following Pattern

For any given matrix find the path from the start to the end which gives the maximum sum. Traverse only right or down. Example: starting index is 15 (left top) and ending index is 10 (bottom right) 15 25 30 45 25 60 70 75 10 O/P:15->45->70->75->10 sum is 215

c++ program to print string along the diagonals of the matrix.