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
explain what is an endless loop?
Differentiate between #include<...> and #include '...'
A collection of data with a given structure for excepting storing and providing on demand data for multiple users a) linked list b) datastructer c) database d) preprocessor
What is the difference between new and malloc functions?
Differentiate fundamental data types and derived data types in C.
What the different types of arrays in c?
what is a constant pointer in C
What is default value of global variable in c?
Why we use int main and void main?
Write a program to find factorial of a number using recursive function.
Is that possible to store 32768 in an int data type variable?
How can you check to see whether a symbol is defined?
What is null pointer in c?
Write a program to check prime number in c programming?
What does %p mean?