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.

Answers were Sorted based on User's Feedback



pgm to reverse string using arrays i.e god is love becomes love is god) (assumption:only space i..

Answer / santhi perumal

#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 ?    14 Yes 2 No

pgm to reverse string using arrays i.e god is love becomes love is god) (assumption:only space i..

Answer / abdur rab

#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

pgm to reverse string using arrays i.e god is love becomes love is god) (assumption:only space i..

Answer / ruchi

#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 ?    1 Yes 5 No

pgm to reverse string using arrays i.e god is love becomes love is god) (assumption:only space i..

Answer / paaru

#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 7 No

Post New Answer

More C Interview Questions

what different between c and c++

1 Answers  


What is oops c?

0 Answers  


#include<stdio.h> void main() { int =1; printf("%d%d%d",a++,++a,++a); }

3 Answers   VB,


WHOT IS CHAR?

4 Answers   TCS,


What is void c?

0 Answers  






a way in which a pointer stores the address of a pointer which stores the value of the target value a) reference b) allocation c) multiple indirection d) none

0 Answers  


a parameter passed between a calling program and a called program a) variable b) constant c) argument d) all of the above

0 Answers  


what is const volatile?

2 Answers  


What is structure in c definition?

0 Answers  


Write a c pgm for leap year

11 Answers   College School Exams Tests, IBM, TCS,


Can two or more operators such as and be combined in a single line of program code?

0 Answers  


What does stand for?

0 Answers  


Categories