Problem statement
Write a program to reverse a string character by character using user defined function.
Here don’t use standard string handling function strrev().
Program to reverse a string without using strlen()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#include<stdio.h> #include<string.h> void ustrrev(char*); int main() { char sstr[20] = "WebEncyclop"; ustrrev(sstr); } void ustrrev(char*s) { char temp[10]; int j=0; int i=strlen(s)-1; while(i >= 0) { temp[j] = s[i]; j--; i--; } temp[j] = '\0'; printf("reverse string is %s",temp); } |
Output
1 |
reverse string is polcycnebew |