Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #65531 > unrolled thread
| Started by | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| First post | 2015-07-14 02:09 +0100 |
| Last post | 2015-07-14 02:09 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.c
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: To reverse the digits of a numeral Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-07-14 02:09 +0100
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2015-07-14 02:09 +0100 |
| Subject | Re: To reverse the digits of a numeral |
| Message-ID | <87twt7mtot.fsf@bsb.me.uk> |
ram@zedat.fu-berlin.de (Stefan Ram) writes:
> To me, it makes non sense to "reverse the digits of a numeral".
>
> When you have stored a numeral, you can read it in any order you
> like. It has no direction! Therefore, it can't be "reversed".
I don't understand this. In this usage of the word numeral it's a
sequence of digits (also sometimes confusingly called numerals). A
sequence has an order and, if it's finite, can be reversed.
> #include <stdio.h> /* putchar */
> #include <string.h> /* strlen */
> #include <stddef.h> /* size_t */
>
> int main( void )
> { char const * const numeral = "123";
> size_t const length = strlen( numeral );
> char const * const numeral_top = numeral + length;
>
> for( char const * p = numeral; p < numeral_top; ++p )
> putchar( *p ); putchar( '\n' );
>
> for( char const * p = numeral_top - 1; p >= numeral; --p )
> putchar( *p ); putchar( '\n' ); }
That's undefined. I'd probably write
const char *p = numeral_top;
while (p > numeral)
putchar(*--p);
but there are obviously loads of alternatives.
<snip>
--
Ben.
Back to top | Article view | comp.lang.c
csiph-web