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 / vignesh1988i

#include<stdio.h>
#include<conio.h>
void main()
{
char str[100],temp;
printf("enter the string :");
gets(str);
for(int i=0,j=0;str[j]!='\0';j++)
{
if(str[j]!=' ')
{
if(str[j+1]==' ')
{
temp=str[j];
str[j]=' ';
str[i]=temp;
i=i+2;
str[i-1]=' ';
}
else if(str[j+1]!=' ')
{
str[i]=str[j];
i++;
}
}
str[i]='\0';
printf("%s",str);
getch();
}

Is This Answer Correct ?    8 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Tell us two differences between new () and malloc ()?

614


what is the different bitween abap and abap-hr?

1741


What is the main difference between calloc () and malloc ()?

573


i have a written test for microland please give me test pattern

2183


Write a program to maintain student’s record. Record should not be available to any unauthorized user. There are three (3) categories of users. Each user has its own type. It depends upon user’s type that which kind of operations user can perform. Their types and options are mentioned below: 1. Admin (Search Record [by Reg. No or Name], View All Records, Insert New Record, Modify Existing Record) 2. Super Admin (Search Record [by Reg. No or Name], View All Records, Insert New Record, Modify Existing Record, Delete Single Record) 3. Guest (Search Record [by Reg. No or Name], View All Records) When first time program runs, it asks to create accounts. Each user type has only 1 account (which means that there can be maximum 3 accounts). In account creation, following options are required: Login Name: <6-10 alphabets long, should be unique> Password: <6-10 alphabets long, should not display characters when user type> Confirm Password: Account Type: Login Name, Password and Account Type should be stored in a separate file in encrypted form. (Encryption means that actual information should be changed and Decryption means that Encrypted information is changed back to the actual information) If any of the above mentioned requirement(s) does not meet then point out mistake and ask user to specify information again. When Program is launched with already created accounts, it will ask for user name and password to authenticate. On successful authentication, give options according to the user’s type.

1513






What is pointer in c?

740


How important is structure in life?

590


A function can make the value of a variable available to another by a) declaring the variable as global variable b) Passing the variable as a parameter to the second function c) Either of the two methods in (A) and (B) d) binary stream

668


What is a sequential access file?

648


typedef enum { html, java, javascript, perl, cgi } lang;The above statement defines a : a) Union b) User defined type c) Enumerated variable d) none

716


What are the rules for identifiers in c?

585


How can I trap or ignore keyboard interrupts like control-c?

620


What is the purpose of 'register' keyword in c language?

627


find the value of y y = 1.5x+3 for x<=2 y = 2x+5 for x>2

1526


What is the function of this pointer?

674