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

a value that does not change during program execution a) variabe b) argument c) parameter d) none

691


define string ?

665


In C language, the variables NAME, name, and Name are all the same. TRUE or FALSE?

766


What is typedef?

666


Tell me what is null pointer in c?

613






Explain how can you tell whether two strings are the same?

580


What is meant by keywords in c?

614


What do you know about the use of bit field?

610


exit () is used to a) exit () terminates the execution of the program itself b) exit () terminates the execution of the loop c) exit () terminates the execution of the block d) none of the above

657


What is string concatenation in c?

566


What is the right type to use for boolean values in c?

581


Tell me is null always defined as 0(zero)?

669


What is the use of volatile?

606


shorting algorithmS

1798


Why clrscr is used in c?

583