Last change
on this file since b8080f6 was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 8 years ago |
Imported original source code.
|
-
Property mode
set to
100755
|
File size:
951 bytes
|
Rev | Line | |
---|
[3ae31e9] | 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 |
|
---|
| 14 | char *
|
---|
| 15 | strrevi(s)
|
---|
| 16 | char *s;
|
---|
| 17 | {
|
---|
| 18 | register char *p1, *p2;
|
---|
| 19 | register long i;
|
---|
| 20 | register char c;
|
---|
| 21 |
|
---|
| 22 | p1 = s; /* initialize left end pointer */
|
---|
| 23 | p2 = s; /* initialize right end pointer */
|
---|
| 24 | i = 0L; /* initialize character count */
|
---|
| 25 |
|
---|
| 26 | while (*p2) { /* find the right end of the string */
|
---|
| 27 |
|
---|
| 28 | ++i;
|
---|
| 29 | ++p2;
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | --p2; /* adjust right end pointer */
|
---|
| 33 | i >>= 1; /* calculate swap count */
|
---|
| 34 |
|
---|
| 35 | while (i--) { /* for each pair of characters ... */
|
---|
| 36 |
|
---|
| 37 | c = *p2; /* ... swap right and left characters */
|
---|
| 38 | *p2-- = *p1;
|
---|
| 39 | *p1++ = c;
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | return(s); /* return pointer to reversed string */
|
---|
| 43 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.