Home Forums C Programming function Reply To: function

#3298
Humayan
Participant

heres one without a loop:

/****************************************************************
* File Name : c:programshelpshell.cpp
* Date : December,19,2007
* Comments : new project
* Compiler/Assembler :
* Program Shell Generated At: 2:21:22 p.m.
=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/

#include < iostream >
//#include < string.h >
//#include < conio.h >
//#include < math.h >
//#include < iomanip >
//#include < ctype.h >
using namespace std;

//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ FUNCTION PROTOTYPES @@@@@@@@@@@@@@@@@@@@@@@@@@
void reverseString ( char * string , int & front , int & rear );
void reverseStringDriver ( char * string , int length );
//##################################################################################

//main function ******************************
int main ( )
{
char string [ 10 ] ;
strcpy ( string , "hellos" );
reverseStringDriver ( string , 6 );
cout << "reversed string : " << string << endl ;
return 0 ;
}
/******************************* FUNCTION DEFINITION ******************************
Name : reverseString
Parameters :
string a(n) char * ( char * ) ,
front a(n) int ( int ) ,
rear a(n) int ( int )
Returns: Void type
Comments:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void reverseString ( char * string , int & front , int & rear )
{

if ( front > rear )
return;
char temp;

temp = string [ front ];
string [ front ] = string [ rear ];
string [ rear ] = temp;

front ++;
rear --;
return;
}
/******************************* FUNCTION DEFINITION ******************************
Name : reverseStringDriver
Parameters :
string a(n) char *

Returns: Void type
Comments:

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void reverseStringDriver ( char * string , int length )
{
int front = 0 , rear = length - 1;
reverseString ( string , front , rear );
return;
}