Guest_imported
New member
- Jan 1, 1970
- 0
Can anyone please revise the following program and yet it will still do the same function. Thanks.
#include <iostream>
#include <string.h>
using namespace std ;
void strReverse ( char *pString ) ;
int main ()
{
char ch[20] ;
cout << "Please enter the string you want to reverse: " ;
cin.getline ( ch, 20 ) ;
strReverse ( ch ) ;
cout << "Your string reversed is: "
<< ch
<< '\n' ;
return 0 ;
}
//
******************************************************************************
****
// Routine: strReverse ()
// Programmer: Luis Lugo
// Purpose: This routine reverses a string
// Parameters: pString - type char * : The string to be left trimmed in
place.
// Returns: Nothing.
//
******************************************************************************
****
void strReverse ( char * pString )
{
int length = strlen( pString ), i, k ;
char tempCh ;
for ( i = 0 , k = length - 1 ; i < length / 2 ; i++ , k-- )
{
tempCh = pString ;
pString = pString [k] ;
pString[k] = tempCh ;
tempCh = NULL ;
}
pString [length] = '\0' ;
}
#include <iostream>
#include <string.h>
using namespace std ;
void strReverse ( char *pString ) ;
int main ()
{
char ch[20] ;
cout << "Please enter the string you want to reverse: " ;
cin.getline ( ch, 20 ) ;
strReverse ( ch ) ;
cout << "Your string reversed is: "
<< ch
<< '\n' ;
return 0 ;
}
//
******************************************************************************
****
// Routine: strReverse ()
// Programmer: Luis Lugo
// Purpose: This routine reverses a string
// Parameters: pString - type char * : The string to be left trimmed in
place.
// Returns: Nothing.
//
******************************************************************************
****
void strReverse ( char * pString )
{
int length = strlen( pString ), i, k ;
char tempCh ;
for ( i = 0 , k = length - 1 ; i < length / 2 ; i++ , k-- )
{
tempCh = pString ;
pString = pString [k] ;
pString[k] = tempCh ;
tempCh = NULL ;
}
pString [length] = '\0' ;
}