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

Write the Program to reverse a string using pointers.

614


Can we declare variables anywhere in c?

576


What is the most efficient way to store flag values?

684


What is void main () in c?

723


Describe the difference between = and == symbols in c programming?

775






How do you use a 'Local Block'?

719


What is integer constants?

615


What are the disadvantages of a shell structure?

686


What is atoi and atof in c?

614


Write a program to print factorial of given number using recursion?

601


What is typeof in c?

603


Explain how many levels deep can include files be nested?

624


Array is an lvalue or not?

635


What is the best way to comment out a section of code that contains comments?

777


Explain what is dynamic data structure?

642