Write a program to remove consecutive spaces from the string.
#include<stdio.h> void Remove_consecutive_spaces(char*); int main() { char s[100]; printf("Enter string = "); scanf("%[^\n]",s); Remove_consecutive_spaces(s); printf("%s\n",s); return 0; } void Remove_consecutive_spaces(char *p) { int i = 0,j=0; for(i=0;p[i];i++) { if(!((p[i] == 32) && (p[i+1] == 32))) p[j++]=p[i]; } p[j]='\0'; }
Output
Enter string = Lot to Learn Lot to Learn Enter string = Lot to Learn Lot to Learn