Given an array of characters, how would you reverse it? How
would you reverse it without using indexing in the array?

Answer Posted / abdur rab

#include <stdio.h>

void reverse ( char* cp_str )
{
char* cp_rev_ptr = NULL;
cp_rev_ptr = cp_str;
while ( ( cp_rev_ptr ) && ( *cp_rev_ptr != '\0' ) )
cp_rev_ptr++;
cp_rev_ptr--;

while ( cp_str < cp_rev_ptr ) {
*cp_str ^= *cp_rev_ptr ^= *cp_str ^=
*cp_rev_ptr;
cp_str++;
cp_rev_ptr--;
}
}

int main ( int argc, char* argv [] )
{
char array [] = {"dlroW olleH"};

printf ("\nBefore :%s", array );
reverse ( array );
printf ("\nAfter :%s", array );

return ( 0 );
}

Output
======
Before :dlroW olleH
After :Hello World

Is This Answer Correct ?    16 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can you please explain the difference between malloc() and calloc() function?

621


Is c is a procedural language?

601


formula to convert 2500mmh2o into m3/hr

499


How many loops are there in c?

582


How can I make sure that my program is the only one accessing a file?

680






Why static variable is used in c?

558


please give me some tips for the placement in the TCS.

1634


What is the Purpose of 'extern' keyword in a function declaration?

654


How is a null pointer different from a dangling pointer?

557


How will you print TATA alone from TATA POWER using string copy and concate commands in C?

920


What do mean by network ?

659


write a program to display all prime numbers

1456


Is c programming hard?

576


Explain about block scope in c?

663


What is spaghetti programming?

670