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

What is the maximum no. of arguments that can be given in a command line in C.?

661


write a proram to reverse the string using switch case?

2460


When a c file is executed there are many files that are automatically opened what are they files?

587


What are external variables in c?

539


Write a program that takes a 5 digit number and calculates 2 power that number and prints it(should not use big integers and exponential functions)

5787






what will be maximum number of comparisons when number of elements are given?

1406


Badboy is defined who has ALL the following properties: Does not have a girlfriend and is not married. He is not more than 23 years old. The middle name should be "Singh" The last name should have more than 4 characters. The character 'a' should appear in the last name at least two times. The name of one of his brothers should be "Ram" Write a method: boolean isBadBoy(boolean hasGirlFriend , boolean isMarried, int age , String middleName , String lastName , String[] brotherName); isHaveGirlFriend is true if the person has a girlfriend isMarried is true if the person is married age is the age of the person middleName is the middle name of the person lastName is the last name of the person brotherName is the array of the names of his brothers

1420


Explain null pointer.

615


What is NULL pointer?

671


How can I dynamically allocate arrays?

585


Tell me when is a void pointer used?

642


How to throw some light on the b tree?

600


Where we use clrscr in c?

694


What are the applications of c language?

619


Why is c known as a mother language?

740