Re: How to print an array of char backward.
- From: Lew Pitcher <lpitcher@xxxxxxxxxxxx>
- Date: Sat, 31 May 2008 12:36:17 -0400
In comp.lang.c, sohijb.edrisy@xxxxxxxxx wrote:
You could reverse the string in place before printing it. There is no
standard string reverse function, but it's easy enough to write one. As
an alternative you could just iterate backwards through the string
while printing it, character by character.
<snip>
Here's what I should do.
(Put this after the do-while{} loop)
////////////////////////////////////////////////////////////////////////
length = strlen(bin);
int i;
for (i = length - 1; i >= 0; i--)
{
printf("%c", bin[i]);
}
///////////////////////////////////////////////////////////////////////
How about...
void RevPrint(char *string)
{
if (*string)
{
RevPrint(string+1);
printf("%c",*string);
}
}
used as...
printf("Binary representation: "); RevPrint(bin);
--
Lew Pitcher
Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------
.
- References:
- How to print an array of char backward.
- From: hank
- Re: How to print an array of char backward.
- From: santosh
- Re: How to print an array of char backward.
- From: sohijb . edrisy
- How to print an array of char backward.
- Prev by Date: Re: How to trace function calls?
- Next by Date: Re: function
- Previous by thread: Re: How to print an array of char backward.
- Next by thread: Re: How to print an array of char backward.
- Index(es):
Relevant Pages
|