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 difference between structure and union in c programming?

1111


Why does not c have an exponentiation operator?

1054


Why c is faster than c++?

1046


Differentiate between a structure and a union.

1292


how to solve "unable to open stdio.h and conio.h header files in windows 7 by using Dos-box software

3325


What is an expression?

1060


What are different types of pointers?

1075


Are there namespaces in c?

1133


How to find a missed value, if you want to store 100 values in a 99 sized array?

1415


Why is structure important for a child?

1105


Differentiate between the expression “++a” and “a++”?

1255


Do you have any idea how to compare array with pointer in c?

1052


Can the “if” function be used in comparing strings?

1056


What is structure of c program?

1168


Are global variables static in c?

1169