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

How many bytes is a struct in c?

725


Tell me about low level programming languages.

644


Can variables be declared anywhere in c?

624


How do we print only part of a string in c?

587


Explain what is the difference between #include and #include 'file' ?

585






pgm to find any error in linklist(in single linklist check whether any node points any of previous nodes instead of next node)

2201


What is meant by errors and debugging?

649


console I/O functions means a) the I/O operations done on disk b) the I/O operations done in all parts c) the input given through keyboard is displayed VDU screen d) none of the above

655


Why doesnt that code work?

600


Explain what is a const pointer?

640


What is the use of ?

626


Differentiate call by value and call by reference?

569


What are the types of bitwise operator?

665


Which is not valid in C a) class aClass{public:int x;}; b) /* A comment */ c) char x=12;

611


How are strings stored in c?

595