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

Write a program which returns the first non repetitive character in the string?

588


Write a program to know whether the input number is an armstrong number.

658


How can I do graphics in c?

582


How can you access memory located at a certain address?

656


What is volatile keyword in c?

571






Tell me about low level programming languages.

631


What is the difference between #include and #include 'file' ?

596


Is printf a keyword?

747


Can static variables be declared in a header file?

606


There seem to be a few missing operators ..

601


the portion of a computer program within which the definition of the variable remains unchanged a) mode b) module c) scope d) none

635


What is the purpose of void in c?

607


what will be maximum number of comparisons when number of elements are given?

1395


Explain the red-black trees?

596


Explain what is the purpose of "extern" keyword in a function declaration?

609