source: buchla-68k/libsm/strrevi.c@ 0c834c5

Last change on this file since 0c834c5 was 0580615, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Point of no return.

  • Property mode set to 100644
File size: 904 bytes
Line 
1/*
2 =============================================================================
3 strrevi.c -- reverse a string in place
4 Version 1 -- 1988-02-03 -- D.N. Lynx Crowe
5
6 char *
7 strrevi(s)
8 char *s;
9
10 Reverses string 's1' in place. Returns 's1'.
11 =============================================================================
12*/
13
14char *strrevi(char *s)
15{
16 register char *p1, *p2;
17 register long i;
18 register char c;
19
20 p1 = s; /* initialize left end pointer */
21 p2 = s; /* initialize right end pointer */
22 i = 0L; /* initialize character count */
23
24 while (*p2) { /* find the right end of the string */
25
26 ++i;
27 ++p2;
28 }
29
30 --p2; /* adjust right end pointer */
31 i >>= 1; /* calculate swap count */
32
33 while (i--) { /* for each pair of characters ... */
34
35 c = *p2; /* ... swap right and left characters */
36 *p2-- = *p1;
37 *p1++ = c;
38 }
39
40 return(s); /* return pointer to reversed string */
41}
Note: See TracBrowser for help on using the repository browser.