Skip to main content

C program to suppress the multiple space and tabs in a line

--> C program to suppress the multiple space and tabs in a line of input to single space,(Dennis Ritchie exercise 1.9 page 19.

#include<stdio.h>

/* Copy and replace multiple blanks and tabs by single space
Autor:- Surendra Patil
Date:- july 9th 2013
*/

int main()
{
int c;
printf("\n enter the input with tabs and spaces \n");
while ((c=getchar()) != EOF) {
  if(c ==' ' || c == '\t') {
     putchar(' ');
     /* squeze all the blanks and tabs */
    while ( ((c = getchar()) != EOF) && (c == ' ' || c == '\t'));
  }
   putchar(c);
}
return 0;
}


Input:-
surendra patil nidasoshi

Output:-
surendra patil nidasoshi

Comments