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 / santhi perumal
#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,k;
char a[100];
printf("Enter the String\n");
gets(a);
printf("The Given String is %s \n",a);
for(i=0; a[i] != '\0';i++)
{
if(a[i] == ' ')
{
for(k=i+1;a[k] != '\0';k++)
{
if(a[i+1] == ' ')
{
for(j=i+1;a[j] != '\0';j++)
{
a[j] = a[j+1];
}
a[j] ='\0';
}
}
}
}
printf("The Resulted String is %s\n ",a);
}
Is This Answer Correct ? | 3 Yes | 4 No |
Post New Answer View All Answers
What is chain pointer in c?
Explain the red-black trees?
What do you mean by invalid pointer arithmetic?
How do I use void main?
How do you determine whether to use a stream function or a low-level function?
Can a pointer be static?
What is calloc()?
Tell us two differences between new () and malloc ()?
What is sizeof int?
What is the difference between malloc() and calloc()?
Is array a primitive data type in c?
What is the difference between arrays and pointers?
When should structures be passed by values or by references?
How do you print an address?
int i=3; this declaration tells the C compiler to a) reserve space in memory to hold the integer value b) associate the name i with this memory location c) store the value 3 at this location d) all the above