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
Write the Program to reverse a string using pointers.
Can we declare variables anywhere in c?
What is the most efficient way to store flag values?
What is void main () in c?
Describe the difference between = and == symbols in c programming?
How do you use a 'Local Block'?
What is integer constants?
What are the disadvantages of a shell structure?
What is atoi and atof in c?
Write a program to print factorial of given number using recursion?
What is typeof in c?
Explain how many levels deep can include files be nested?
Array is an lvalue or not?
What is the best way to comment out a section of code that contains comments?
Explain what is dynamic data structure?