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       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
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
pgm to reverse string  using arrays i.e god is love becomes 
love is god)
(assumption:only space is used for seperation of words)

no addtional memory used.i.e no temporary arrays can used.
 Question Submitted By :: Soumya Joy
I also faced this Question!!     Rank Answer Posted By  
 
  Re: pgm to reverse string using arrays i.e god is love becomes love is god) (assumption:only space is used for seperation of words) no addtional memory used.i.e no temporary arrays can used.
Answer
# 1
#include<stdio.h>
#include<conio.h>

int main()
{

    int i,j,length;
	char a[] = "god is love";

	length = strlen(a);
	
	printf("The Given String is\n%s\n",a);
	printf("The Resulted String is\n");

	for(i=length-1;i>=0;i--)
	{
		if(a[i] == ' ')
		{
			for(j=i+1; a[j] != ' ' && a[j] != '\0';j++)
			{
				printf("%c",a[j]);
			}
			printf("%c",a[i]);
		}
	}
	i++;
	while(a[i] !=' ')
	{
		printf("%c",a[i]);
		i++;
	}
	printf("\n");

}
 
Is This Answer Correct ?    3 Yes 1 No
Santhi Perumal
 
  Re: pgm to reverse string using arrays i.e god is love becomes love is god) (assumption:only space is used for seperation of words) no addtional memory used.i.e no temporary arrays can used.
Answer
# 2
#include <stdio.h>

void reverse_string ( char* cp_string, int start, int end )
{
	if ( cp_string && ( start < end ) ) {
		*( cp_string + start ) ^= *( cp_string + 
end  ) 
			^=  *( cp_string + start ) ^= *( 
cp_string + end );
		reverse_string ( cp_string, ++start, --
end ); 
	}
}


int main ( int argc, char* argv [] )
{
	char ca_array [12]={"Hello World"};
	char* cp_ptr = NULL;
	char* cp_ptr_temp = NULL;
	
	printf ( "\n Before Reverse :%s", ca_array );

	reverse_string ( ca_array, 0, strlen ( ca_array ) -
1 );

	cp_ptr_temp = cp_ptr = ca_array;
	while ( NULL != ( cp_ptr_temp = (char*) strchr ( 
cp_ptr_temp, ' ' ) ) ) {
		reverse_string ( cp_ptr, 0, ( cp_ptr_temp - 
cp_ptr ) - 1 );
		cp_ptr = ++cp_ptr_temp;
	}
	// change the final word
	reverse_string ( cp_ptr, 0, ( ( strlen ( 
ca_array ) - 1 ) - ( cp_ptr - ca_array ) ) );

	printf ( "\n After Reverse by Words :%s", 
ca_array );
	return ( 0 );
}
 
Is This Answer Correct ?    1 Yes 0 No
Abdur Rab
 
 
 
  Re: pgm to reverse string using arrays i.e god is love becomes love is god) (assumption:only space is used for seperation of words) no addtional memory used.i.e no temporary arrays can used.
Answer
# 3
#include<stdio.h>
#include<conio.h>
int main()
{
int i=0,c;
char a[20];
printf("\nEnter the string");
while((a[i++]=getchar())!='\n');
printf("\nReverse of the string is ");
for(c=i;c>=0;c++)
{
printf("%c"a[c]);
}
getch();
}
 
Is This Answer Correct ?    0 Yes 2 No
Ruchi
 
  Re: pgm to reverse string using arrays i.e god is love becomes love is god) (assumption:only space is used for seperation of words) no addtional memory used.i.e no temporary arrays can used.
Answer
# 4
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[20],i;
printf("\n\nEnter the string:");
gets(a);
for(i=strlen(a)-1;i>=0;i++)
{
 printf("%d"a[i]);
}
getch();
}
 
Is This Answer Correct ?    1 Yes 1 No
Paaru
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
write a program in 'c' to find the value of p[i+1]^n.p,i,n are arguments of a macro and n is a integer  1
Identify the correct argument for the function call fflush () in ANSI C: A)stdout B)stdin C)stderr D)All the above Accenture3
prototype of sine function. Cadence2
difference between memcpy and strcpy  1
Write a program to remove the C comments(/* */) and C++ comments(//) from a file. The file should be declared in command line. Subex2
main is a predefined or user define function if user defined why? if predefined whay? TCS2
What is the output for the following program #include<stdio.h> main() { char a[5][5],flag; a[0][0]='A'; flag=((a==*a)&&(*a==a[0])); printf("%d\n",flag); } ADITI5
how to convert an char array to decimal array  3
What is structure padding & expalain wid example what is bit wise structure?  1
main() { int i=1; while (i<=5) { printf("%d",i); if (i>2) goto here; i++; } } fun() { here: printf("PP"); } ME3
How can I access memory located at a certain address?  2
int a=1,b=2,c=3; printf("%d,%d",a,b,c); What is the output? Verifone14
struct ptr { int a; char b; int *p; }abc; what is d sizeof structure without using "sizeof" operator?? Verifone8
How the C program can be compiled? HP7
what is a headerfile?and what will be a program without it explain nan example? Assurgent5
which of the function operator cannot be over loaded a) <= b)?: c)== d)* HCL7
how we can make 3d venturing graphics on outer interface Microsoft1
How to implement call back functions ? HP2
convert 0.9375 to binary CTS1
what is array? HCL22
 
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