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 / vignesh1988i

#include<stdio.h>
#include<conio.h>
void main()
{
char str[100],temp;
printf("enter the string :");
gets(str);
for(int i=0,j=0;str[j]!='\0';j++)
{
if(str[j]!=' ')
{
if(str[j+1]==' ')
{
temp=str[j];
str[j]=' ';
str[i]=temp;
i=i+2;
str[i-1]=' ';
}
else if(str[j+1]!=' ')
{
str[i]=str[j];
i++;
}
}
str[i]='\0';
printf("%s",str);
getch();
}

Is This Answer Correct ?    8 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the back slash character constants or escape sequence charactersavailable in c?

686


hello freinds next week my interview in reliance,nybody has an idea about it intervew questions..so tell

1673


1. Write a function to display the sum of two numbers in the following ways: By using (i) pass by value (ii) pass by address a. function with argument and with return value b. function with argument and without return value c. without argument , with return value d. without argument , without return value Note: Use pass by address.

2337


How can I read and write comma-delimited text?

621


Explain the use of 'auto' keyword

679






What do you mean by Recursion Function?

631


Explain the use of #pragma exit?

699


Describe the complexity of Binary search, Quicksort and various other sorting and searching techniques..

646


What is meant by operator precedence?

678


main() { inta=10,b=20; a>=5?b=100:b=200; printf("%d ",b); }

912


Draw a diagram showing how the operating system relates to users, application programs, and the computer hardware ?

2121


What is a list in c?

621


What are types of functions?

567


What are c header files?

581


What is the use of ?: Operator?

666