ccplusplus.com
Learn C, C++ Concepts
Sunday, September 11, 2011
reverse string using pointers in c
/****************************************************** * File : reverse-stringToReverse-using-pointers.c * Author : Saurabh Gupta * Desc : reverse the given string using pointers * Source : http://saurabhgupta0527.blogspot.com/ * Created : AM 10:11 11 September 2011 * Note : *****************************************************/ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> void reverseString(char* begin){ char temp; char* end; end = begin + strlen(begin)-1; while(end > begin){ temp = *end; *end = *begin; *begin = temp; end--; begin++; } } int main(){ char *stringToReverse; char ch; int i; printf ("enter the stringToReverse\n"); gets (stringToReverse); printf ("stringToReverse =\t%s\n", stringToReverse); reverseString(stringToReverse); printf("reverses string\t=\t%s\n", stringToReverse); return 0; } /* * OUTPUT * [sgupta@rhel54x64 c]$ gcc reverse-string-using-pointers_1.c -o reverse-string-using-pointers_1 [sgupta@rhel54x64 c]$ ./reverse-string-using-pointers_1 enter the stringToReverse stringToReverse = http://saurabhgupta0527.blogspot.com/ reverses string = /moc.topsgolb.7250atpughbaruas//:ptth [sgupta@rhel54x64 c]$ */
See also
Other popular tricky C Sample Codes and language Concept
.
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment