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
Write a program which returns the first non repetitive character in the string?
Write a program to know whether the input number is an armstrong number.
How can I do graphics in c?
How can you access memory located at a certain address?
What is volatile keyword in c?
Tell me about low level programming languages.
What is the difference between #include and #include 'file' ?
Is printf a keyword?
Can static variables be declared in a header file?
There seem to be a few missing operators ..
the portion of a computer program within which the definition of the variable remains unchanged a) mode b) module c) scope d) none
What is the purpose of void in c?
what will be maximum number of comparisons when number of elements are given?
Explain the red-black trees?
Explain what is the purpose of "extern" keyword in a function declaration?