Last change
on this file since 0292fbb was 0580615, checked in by Thomas Lopatic <thomas@…>, 8 years ago |
Point of no return.
|
-
Property mode
set to
100644
|
File size:
837 bytes
|
Rev | Line | |
---|
[f40a309] | 1 | /*
|
---|
| 2 | =============================================================================
|
---|
| 3 | strrev.c -- reverse a string
|
---|
| 4 | Version 1 -- 1988-02-03 -- D.N. Lynx Crowe
|
---|
| 5 |
|
---|
| 6 | char *
|
---|
| 7 | strrev(s1, s2)
|
---|
| 8 | char *s1;
|
---|
| 9 | char *s2;
|
---|
| 10 |
|
---|
| 11 | Copies string 's2' into 's1'. 's1' must be large enough
|
---|
| 12 | to hold 's2'. Returns 's1'.
|
---|
| 13 | =============================================================================
|
---|
| 14 | */
|
---|
| 15 |
|
---|
[0580615] | 16 | char *strrev(char *s1, char *s2)
|
---|
[f40a309] | 17 | {
|
---|
| 18 | register char *s3;
|
---|
| 19 | register long i;
|
---|
| 20 |
|
---|
| 21 | i = 0L; /* initialize string length */
|
---|
| 22 | s3 = s1; /* initialize target left end pointer */
|
---|
| 23 |
|
---|
| 24 | while (*s2) { /* find right end of source string */
|
---|
| 25 |
|
---|
| 26 | ++s2;
|
---|
| 27 | ++i;
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | --s2; /* adjust source right end pointer */
|
---|
| 31 |
|
---|
| 32 | while (i--) /* copy string in reverse */
|
---|
| 33 | *s3++ = *s2--;
|
---|
| 34 |
|
---|
| 35 | *s3 = '\0'; /* terminate the string */
|
---|
| 36 | return(s1); /* return address of reversed string */
|
---|
| 37 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.