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 difference between structure and union in c programming?
Why does not c have an exponentiation operator?
Why c is faster than c++?
Differentiate between a structure and a union.
how to solve "unable to open stdio.h and conio.h header files in windows 7 by using Dos-box software
What is an expression?
What are different types of pointers?
Are there namespaces in c?
How to find a missed value, if you want to store 100 values in a 99 sized array?
Why is structure important for a child?
Differentiate between the expression “++a” and “a++”?
Do you have any idea how to compare array with pointer in c?
Can the “if” function be used in comparing strings?
What is structure of c program?
Are global variables static in c?