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 is %s and %d in c?
given post order,in order construct the corresponding binary tree
Did c have any year 2000 problems?
What are the types of unary operators?
In which header file is the null macro defined?
What does the c in ctime mean?
Can a pointer be volatile in c?
Do you know the difference between exit() and _exit() function in c?
What header files do I need in order to define the standard library functions I use?
What are the characteristics of arrays in c?
What is pointer and structure in c?
What is pass by reference in c?
How can I use a preprocessorif expression to ?
Why do we use stdio h and conio h?
A float occupies 4 bytes in memory. How many bits are used to store exponent part? since we can have up to 38 number for exponent so 2 ki power 6 6, 6 bits will be used. If 6 bits are used why do not we have up to 64 numbers in exponent?