Below is C program to String Reverse - STRREV.
Program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | /* STRING REVERSE - STRREV */ #include<stdio.h> int main() { char str[100]; int i,j; char c; printf ( "Please enter a string: " ); // gets(str); // fgets is a better option over gets to read multiword string . fgets (str, 100, stdin); // Following can be added for extra precaution for '\n' character // if(str[length(str)-1] == '\n') str[strlen(str)-1]=NULL; for (i=0;str[i];i++); for (j=0,i--;j < i;j++,i--) { c=str[i]; str[i]=str[j]; str[j]=c; } printf ( "Reversed string is: %s" ,str); return 0; } |
No comments:
Post a Comment