Home Forums C Programming function Re: Function

#3297
Humayan
Participant

try:


/****************************************************************
* File Name : c:programshelpshell.cpp
* Date : December,18,2007
* Comments : new project
* Compiler/Assembler :
* Program Shell Generated At: 3:35:40 p.m.
=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
#include
#include
//#include
//#include
//#include
//#include
using namespace std;

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

//main function ******************************
int main ( )
{
char string [ 13 ];
strcpy ( string , "hello theres" );
reverseString ( string , 12 );
cout << "reversed string: " << string << endl;

return 0 ;
}

/******************************* FUNCTION DEFINITION ******************************
Name : reverseString
Parameters :
string a(n) char * ( char * )

Returns: user defined type , void
Comments:

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void reverseString ( char * string , int length )
{
int i = length - 1;
int j = 0;
char temp;
while ( j <= i )
{
temp = string [ j ];
string [ j ] = string [ i ];
string [ i ] = temp;
j ++;
i --;
}
return;
}