reversing string function
-
Help me please i need to write function that reversing string, based on description : str * revers(char * source) Thanks in advance !
-
this will do.... char* revers(char * source) { int nCount = strlen( source); char *pRev = new char[ nCount + 1 ]; for( int nIdx = 0;nIdx < nCount + 1;nIdx++) { pRev[ nIdx ] = source[ nCount - 1 - nIdx ]; } return pRev; } nave
Assuming you're using the MS compiler, why not just view the CRT library source?
-
Assuming you're using the MS compiler, why not just view the CRT library source?
-
I would advise you to do that (your own homework yourself). You see, the code Naveen R provided contains some potentially hazardous "features", is highly sub-optimal, and will surely get you in big trouble when you try to explain it to your teacher. Here is my contribution: char* reverse_string(char* s) { char* p=0; while(s) *p=*s; return p; } If you can't get this code to reverse the string this may mean you should study harder :-)