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
Why c is a mother language?
Which of the following operators is incorrect and why? ( >=, <=, <>, ==)
What is a pragma?
Does c have enums?
how many types of operators are include in c language a) 4 b) 6 c) 8 d) 12
What is the difference between the expression “++a” and “a++”?
What is a struct c#?
How do you print only part of a string?
Why & is used in c?
Write a program to swap two numbers without using third variable in c?
What is a lvalue
Here is a good puzzle: how do you write a program which produces its own source code as output?
Explain how does flowchart help in writing a program?
What is the meaning of && in c?
"%u" unsigned integer print the a) address of variable b) value of variable c) name of a variable d) none of the above