summaryrefslogtreecommitdiff
path: root/reference/C/EXAMPLES/reverse.c
blob: 9532e93e600b29e1501e702b07f5889452f178e0 (plain)
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
29
30
/*********************************************************************
 *
 * Purpose: Reverse characters in a string.
 * Author:  K&R
 * Date:    
 *
 *********************************************************************/

void reverse(char s[]);

main()
{
  char text[80]="martin";

  printf("string is %s\n", text);
  reverse(text);
  printf("string is %s\n", text);
}

void reverse(char s[])
{
  int c, i, j;
   
  for (i=0, j=strlen(s)-1; i < j;i++, j--)
  {
    c = s[i];
    s[i] = s [j];
    s[j] = c;
  }
}