Write a program that accepts a string where multiple spaces
are given in between the words. Print the string ignoring
the multiple spaces.

Example:
Input: ā€œ We.....Are....Student ā€œ Note: one .=1 Space
Output: "We Are Student"

Answer Posted / pramod

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main()
{
int i,j,k,len;
char a[100];

printf("Enter the String\n");
gets(a);
printf("The Given String is %s \n",a);
len=strlen(a);
for(i=0; i<len;i++)
{
if(a[i] == ' ')
{
if(a[i+1]==' ')
{
int j=i+1;
while(a[j]==' ')
{
j++;
len--;
}
for(k=i+1;a[j]!=NULL;)
{
a[k++]=a[j++];
}
}
}
}
a[i]='\0';
printf("The Resulted String is %s\n ",a);

}

Is This Answer Correct ?    5 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

5 Write an Algorithm to find the maximum and minimum items in a set of ā€˜nā€™ element.

1581


What is scope rule in c?

603


How can I recover the file name given an open stream or file descriptor?

592


explain what is a newline escape sequence?

683


What is the use of structure padding in c?

562






Why calloc is better than malloc?

570


how logic is used

1496


Define Array of pointers.

631


Is main is user defined function?

592


What are Macros? What are its advantages and disadvantages?

643


write a program to display all prime numbers

1453


What is %s and %d in c?

588


Which type of language is c?

646


When should I declare a function?

621


What is #line?

607