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 / vadivel t

Hi all,

Its enough to have this much length of code below. And I
feel no need to have any temp variables(but i used one temp
pointer).

#include<stdio.h>
main()
{
char *p, *q, *q1;
p = (char *)malloc(100);
q = (char *)malloc(100);
q1 = q;
printf("ENTER THE SENTENCE WITH MULTIPLE SPACES: \n");
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 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between NULL and NUL?

728


What does c mean in basketball?

563


What is cohesion in c?

542


What are the application of void data type in c?

716


What is string in c language?

625






Is null a keyword in c?

737


Why is %d used in c?

567


How can I swap two values without using a temporary?

617


Explain how can I make sure that my program is the only one accessing a file?

625


Explain what are the standard predefined macros?

651


how to build a exercise findig min number of e heap with list imlemented?

1612


What is %d called in c?

761


What is the difference between scanf and fscanf?

664


What's the difference between constant char *p and char * constant p?

657


what do you mean by enumeration constant?

599