ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   To Refer this Site to Your Friends   Click Here
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
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"
 Question Submitted By :: Nish
I also faced this Question!!     Rank Answer Posted By  
 
  Re: 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
# 1
#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 ?    0 Yes 0 No
Vignesh1988i
 
  Re: 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
# 2
#include<stdio.h>
#include<conio.h>

int main()
{
	int i,j,k;
	char a[100];

	printf("Enter the String\n");
	gets(a);

	printf("The Given String is %s \n",a);

	for(i=0; a[i] != '\0';i++)
	{
		if(a[i] == ' ')
		{
			for(k=i+1;a[k] != '\0';k++)
			{
			   if(a[i+1] == ' ')
			   {
			     for(j=i+1;a[j] != '\0';j++)
				 {
				   a[j] = a[j+1];
				 }
			   a[j] ='\0';
			   }
			}
		}
	}
		printf("The Resulted String is %s\n ",a);

}
 
Is This Answer Correct ?    1 Yes 0 No
Santhi Perumal
 
 
 
  Re: 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
# 3
int main()
{
	int i,j,k;
	char a[100];

	printf("Enter the String\n");
	gets(a);

	printf("The Given String is %s \n",a);

	for(i=0; a[i] != '\0';i++)
	{
		if(a[i] == ' ')
		{
			for(k=i+1;a[k] != '\0';k++)
			{
			   if(a[k] == ' ')
			   {
			     for(j=k;a[j] != '\0';j++)
				 {
				   a[j] = a[j+1];
				 }
			   a[j] ='\0';
			   }
			}
		}
	}
		printf("The Resulted String is %s\n ",a);

}
 
Is This Answer Correct ?    1 Yes 0 No
Vikramaditya.n
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
what is diff between localstatic and globalstatis variable possible 2 use in another file...? HCL2
dibakar & vekatesh..uttejana here..abt ur reply for in place reversal of linked list..wats p stands for there?  1
#ifdef TRUE int I=0; #endif main() { int j=0; printf("%d %d\n",i,j); } ADITI2
what is the difference between normal variables and pointer variables.............. Satyam4
What are .h files and what should I put in them?  3
print the following using nested for loop. 5 4 3 2 1 1 2 3 4 3 2 1 1 2 1 2 1 1 2 3 4 3 2 1 1 2 3 4 5  4
What is the result main() { char c=-64; int i=-32 unsigned int u =-16; if(c>i){ printf("pass1,"); if(c<u) printf("pass2"); else printf("Fail2");} else printf("Fail1); if(i<u) printf("pass2"); else printf("Fail2") } a)Pass1,Pass2 b)Pass1,Fail2 c)Fail1,Pass2 d)Fail1,Fail2 e)none IBM7
What is the most efficient way to count the number of bits which are set in a value?  2
what is the output of below pgm? void main() { int i=0; if(i) printf("pass"); else printf("fail"); }  2
int *a[5] refers to TCS7
Please list all the unary and binary operators in C.  1
Write the program for displaying the ten most frequent words in a file such that your program should be efficient in all complexity measures. Google3
Write a program in c to input a 5 digit number and print it in words.  1
what is object oriental programing?  1
How can I invoke another program from within a C program?  1
How the processor registers can be used in C ? HP4
difference between i++* and *++i IBM2
#define swap1(a,b) a=a+b;b=a-b;a=a-b; main() { int x=5,y=10; swap1(x,y); printf("%d %d\n",x,y); swap2(x,y); printf("%d %d\n",x,y); } int swap2(int a,int b) { int temp; temp=a; b=a; a=temp; return; } what are the outputs? Ramco4
what is the difference between const volatile int i & volatile const int j; HCL1
Can u return two values using return keyword? If yes, how? If no, why?  6
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com