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
What are the back slash character constants or escape sequence charactersavailable in c?
hello freinds next week my interview in reliance,nybody has an idea about it intervew questions..so tell
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.
How can I read and write comma-delimited text?
Explain the use of 'auto' keyword
What do you mean by Recursion Function?
Explain the use of #pragma exit?
Describe the complexity of Binary search, Quicksort and various other sorting and searching techniques..
What is meant by operator precedence?
main() { inta=10,b=20; a>=5?b=100:b=200; printf("%d ",b); }
Draw a diagram showing how the operating system relates to users, application programs, and the computer hardware ?
What is a list in c?
What are types of functions?
What are c header files?
What is the use of ?: Operator?