Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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 an example of structure?

981


a c variable cannot start with a) an alphabet b) a number c) a special symbol d) both b and c above

1171


What is the use of pointers in C?

1024


hi send me sample aptitude papers of cts?

2106


What are preprocessor directives in c?

1033


PLS U SENS ME INTERVIEW O. MY EMAIL ADD, SOFIYA.SINGH@GMAIL.COM

2145


What is the purpose of void in c?

992


What are the basic data types associated with c?

1220


To print the pattern 1 2 3 4 5 10 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9

2598


What is use of integral promotions in c?

1074


What is data types?

1020


Suggesting that there can be 62 seconds in a minute?

996


Is fortran still used in 2018?

986


Do pointers store the address of value or the actual value of a variable?

1020


Why is c called "mother" language?

1231