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


Please Help Members By Posting Answers For Below Questions

What is chain pointer in c?

591


Explain the red-black trees?

596


What do you mean by invalid pointer arithmetic?

623


How do I use void main?

619


How do you determine whether to use a stream function or a low-level function?

633






Can a pointer be static?

605


What is calloc()?

617


Tell us two differences between new () and malloc ()?

605


What is sizeof int?

622


What is the difference between malloc() and calloc()?

607


Is array a primitive data type in c?

566


What is the difference between arrays and pointers?

620


When should structures be passed by values or by references?

569


How do you print an address?

725


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

734