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
What is the difference between NULL and NUL?
What does c mean in basketball?
What is cohesion in c?
What are the application of void data type in c?
What is string in c language?
Is null a keyword in c?
Why is %d used in c?
How can I swap two values without using a temporary?
Explain how can I make sure that my program is the only one accessing a file?
Explain what are the standard predefined macros?
how to build a exercise findig min number of e heap with list imlemented?
What is %d called in c?
What is the difference between scanf and fscanf?
What's the difference between constant char *p and char * constant p?
what do you mean by enumeration constant?