Implement the following function which accepts a string as parameter and reverses it, without using any function
from the string library.
void strReverse(char *str)
#define MAX_LEN 500
void strReverse(char *str)
{
int n=0,k;
char temp[MAX_LEN];
while(*(str+n)!='\0') n++;
for(k=0;k<n;k++) temp[k] = *(str+n-k-1);
printf("\n\nString in reverse order: %s",temp);
}
main(void)
{
char InputStr[MAX_LEN];
printf("\nEnter text/string: ");
scanf("%[^\n]",InputStr);
strReverse(&InputStr[0]);
return(0);
}
Comments
Leave a comment