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 string functions? List some string functions available in c.
What does the error message "DGROUP exceeds 64K" mean?
What does != Mean in c?
What is the -> in c?
What is #include stdio h and #include conio h?
What is difference between function overloading and operator overloading?
can anyone suggest some site name..where i can get some good data structure puzzles???
What tq means in chat?
Why is c so important?
What does emoji p mean?
Why is c platform dependent?
What is an lvalue?
What does %2f mean in c?
What are the different types of errors?
In C language, the variables NAME, name, and Name are all the same. TRUE or FALSE?