ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
1:   #include <stdio.h>
 2:   #include <stdlib.h>
 3:
 4:   void reverseString(char str[]) {
 5:        int i;
 6:        char temp;
 7:
 8:        for (i = 0; i < (strlen(str)/2); i++) {
 9:            temp = str[strlen(str)-1-i];
10:            str[strlen(str)-1-i] = str[i];
11:            str[i] = temp;
12:        }
13:   }
14:
15:   int main() {
16:       char str[10];
17:
18:       printf("Enter name: ");
19:       gets(str);
20:
21:     printf("Length of string : %dn",
    strlen(str));
22:     reverseString(str);
23:     printf("After reverse string : %sn",
    str);
24:
25:     printf("nn");
26:     system("PAUSE");
27:     return 0;
28: }
29:

More Related Content

Reverse string

  • 1. 1: #include <stdio.h> 2: #include <stdlib.h> 3: 4: void reverseString(char str[]) { 5: int i; 6: char temp; 7: 8: for (i = 0; i < (strlen(str)/2); i++) { 9: temp = str[strlen(str)-1-i]; 10: str[strlen(str)-1-i] = str[i]; 11: str[i] = temp; 12: } 13: } 14: 15: int main() { 16: char str[10]; 17: 18: printf("Enter name: "); 19: gets(str); 20: 21: printf("Length of string : %dn", strlen(str)); 22: reverseString(str); 23: printf("After reverse string : %sn", str); 24: 25: printf("nn"); 26: system("PAUSE"); 27: return 0; 28: } 29: