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 “
Output: "We Are Student"

Answer Posted / vadivel t

#include<stdio.h>
main()
{
char *p, *q, *q1;
p = (char *)malloc(200);
q = (char *)malloc(200);
q1 = q;
printf("ENTER THE SENTENCE: \n");
p = gets(p);
while(*p != '\0')
{
if(*p != ' ' || *(q -1) != ' ')
{
*q++ = *p++;
}
else
p++;
}
*q = '\0';
printf("%s", q1);
getch();
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the advantages of external class?

590


Can main () be called recursively?

623


Write a program to find the biggest number of three numbers in c?

588


what will be maximum number of comparisons when number of elements are given?

1408


Is python a c language?

550






What are disadvantages of C language.

640


Is there any algorithm to search a string in link list in the minimum time?(please do not suggest the usual method of traversing the link list)

1862


#include #include struct stu { int i; char j; }; union uni { int i; char j; }; void main() { int j,k; clrscr(); struct stu s; j=sizeof(s); printf("%d",j); union uni u; k=sizeof(u); printf("%d",k); getch(); } what is value of j and k.

5192


What is the difference between procedural and declarative language?

645


What is the value of a[3] if integer a[] = {5,4,3,2,1}?

664


What is null character in c?

684


What are global variables and how do you declare them?

614


What does 3 periods mean in texting?

595


Explain what header files do I need in order to define the standard library functions I use?

645


What is cohesion and coupling in c?

587