473,396 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

reverse string, how to print string and not decimals?

char* reverse(char* str) {
int length = strlen(str);
char* acc[length];
int i;
for (i=0; i<=length-1; i++){
acc[length-1-i] = str[i];
}
return acc;
}

How do I then print a string and not decimals? If I add printf inside
the for loop it prints decimals. they are reversed so it works but I
want to prin chars.
Aug 5 '08 #1
38 2662
ssecorp wrote:
char* reverse(char* str) {
int length = strlen(str);
char* acc[length];
int i;
for (i=0; i<=length-1; i++){
acc[length-1-i] = str[i];
}
return acc;
}

How do I then print a string and not decimals? If I add printf inside
the for loop it prints decimals. they are reversed so it works but I
want to prin chars.
Show us the code. There is no printf() in what you have.


Brian
Aug 5 '08 #2

"Default User" <de***********@yahoo.comwrote in message
news:6f************@mid.individual.net...
> char* acc[length];
Oops!
Aug 5 '08 #3
Mark B [Diputsur] wrote:
>
"Default User" <de***********@yahoo.comwrote in message
news:6f************@mid.individual.net...
char* acc[length];

Oops!
I most certainly did NOT write that.

Brian
Aug 5 '08 #4
In comp.lang.c, ssecorp wrote:
char* reverse(char* str) {
int length = strlen(str);
char* acc[length];
acc is an array of pointers to characters. Are you /positive/ that this is
what you want. I don't think it is.
int i;
for (i=0; i<=length-1; i++){
acc[length-1-i] = str[i];
}
return acc;
Are you /certain/ that you want to return an array of pointers to
characters? Wouldn't you rather return a single pointer to a character?
}
How do I then print a string and not decimals?
Huh?
If I add printf inside the for loop it prints decimals.
Then you did it wrong. In any case, it makes no sense to put a printf()
inside your reversal loop.
they are reversed so it works but I want to prin chars.
Yes? So?

First off, correct your string reversal function. You want something like...

char *reverse(char *str)
{
char *start, *end, temp;

for (end=str;*end;++end); /* point end at end-of-string */
--end; /* point end at last-character-in-string */
for (start=str; /* point start at first-character-in-string */
start < end; /* loop until start passes end */
++start, --end) /* move start up, end down */
{
temp = *start; /* save the character at start */
*start = *end; /* put character at end into place at start */
*end = temp; /* put saved start character into place at end */
}
return str; /* return pointer to first character */
}

Then, you can do something like...

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
char text[] = "This is a test";

printf("Normal: \"%s\"\n",text);
printf("Reversed: \"%s\"\n",reverse(text));

return EXIT_SUCCESS;
}

and see that the reverse() function does indeed reverse any modifiable text
string.

--
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. ------
Aug 5 '08 #5
Default User said:
Mark B [Diputsur] wrote:
>>
"Default User" <de***********@yahoo.comwrote in message
news:6f************@mid.individual.net...
> char* acc[length];

Oops!

I most certainly did NOT write that.
Right - you merely quoted it, and we all do that, obviously. (Use-mention
distinction.)

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Aug 5 '08 #6

"Default User" <de***********@yahoo.comwrote in message
news:6f************@mid.individual.net...
Mark B [Diputsur] wrote:
>>
"Default User" <de***********@yahoo.comwrote in message
news:6f************@mid.individual.net...
> char* acc[length];

Oops!

I most certainly did NOT write that.
No, but you quoted it, and rather than looking
at the code and finding the error, you asked for
additional information, while his problem was
looking you right in the face... no?


Aug 5 '08 #7
On Aug 5, 3:19 pm, ssecorp <circularf...@gmail.comwrote:
char* reverse(char* str) {
int length = strlen(str);
char* acc[length];
int i;
for (i=0; i<=length-1; i++){
acc[length-1-i] = str[i];
}
return acc;

}

How do I then print a string and not decimals? If I add printf inside
the for loop it prints decimals. they are reversed so it works but I
want to prin chars.
What do you mean by "decimals"? If you're using printf() like
'printf("%d", str[i])', then yes, it will print something like
numbers, since the conversion specification '%d' is for integers, not
for chars. Use '%c', or simply putchar().

Also, your function returns a pointer to a local object, which will be
deallocated when the function returns, and thus what it returns will
point to nothing. What you want is probably a function that modifies
the string "in place."

Sebastian

Aug 5 '08 #8
ssecorp <ci**********@gmail.comwrote:
char* reverse(char* str) {
int length = strlen(str);
char* acc[length];
This is problematic for at least four reasons:

a) The size of an array must be a compile-time constant unless
you have a compiler that supports C99 variable length arrays
b) You ask for 'length' pointers to char, but it looks very
much as if you just want an array of chars
c) If 'acc' would be an array of chars it would be too short by
one element if you want to store a string with the same length
as that of 'str' in it (don't forget about the trailing '\0'
char that is needed to make a string out of a mere char array)
d) You later try to pass back a pointer to the array to the caller
but this array is a local variable that vanishes the moment the
function is left and then can't be used anymore.

There are basically two ways you can get aroung the last problem.

1) Have the caller pass a second array to the function in which
you store the reversed string
2) Allocate memory for the reversed string (and tell everyone
that's going to use this function to deallocate it when it's
not needed anymore).

A third approach would be to have a static array that's long
enough for each string you will pass to this function. But there
are two difficulties. First of all knowing in advance what the
longest string that ever will be passed to the function can be
tricky ti say the least. And the reversed string can only be used
between two invokations of the function since the next invokation
will overwrite the previous result.
int i;
for (i=0; i<=length-1; i++){
acc[length-1-i] = str[i];
}
If 'acc' would be an array of chars (of sufficient length) it
now would contain the reversed chars from 'str'. But it's still
missing a trailing '\0' char and thus it's not a string.
return acc;
And that's, as I wrote, absolutely wrong. You can't safely pass
back a pointer to a local variable for use in the caller.
}
How do I then print a string and not decimals? If I add printf inside
the for loop it prints decimals. they are reversed so it works but I
want to prin chars.
No idea what this means. Show your printf() call and you probably
will get an answer. But without knowing what exactly you did there
it's impossible to say.
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
Aug 5 '08 #9
Mark B [Diputsur] wrote:
>
"Default User" <de***********@yahoo.comwrote in message
news:6f************@mid.individual.net...
Mark B [Diputsur] wrote:
>
"Default User" <de***********@yahoo.comwrote in message
news:6f************@mid.individual.net...
>
char* acc[length];
>
Oops!
I most certainly did NOT write that.

No, but you quoted it,
So? You removed the attribution from the person who DID write it and
said that I did.
and rather than looking
at the code and finding the error, you asked for
additional information, while his problem was
looking you right in the face... no?
No. Without complete code that has a chance of demonstrating his
problem, why waste my time?

Brian
Aug 5 '08 #10
Richard Heathfield wrote:
Default User said:
Mark B [Diputsur] wrote:
>
"Default User" <de***********@yahoo.comwrote in message
news:6f************@mid.individual.net...

char* acc[length];

Oops!
I most certainly did NOT write that.

Right - you merely quoted it, and we all do that, obviously.
(Use-mention distinction.)

I fail to understand your point.


Brian
Aug 5 '08 #11
Default User said:
Mark B [Diputsur] wrote:
>>
"Default User" <de***********@yahoo.comwrote in message
news:6f************@mid.individual.net...
Mark B [Diputsur] wrote:
"Default User" <de***********@yahoo.comwrote in message
news:6f************@mid.individual.net...

char* acc[length];

Oops!

I most certainly did NOT write that.

No, but you quoted it,

So? You removed the attribution from the person who DID write it
Yes, he did, but...
and said that I did.
....no, he didn't do that, not as far as anyone is concerned who retains the
ability to count quote-markers.
>and rather than looking
at the code and finding the error, you asked for
additional information, while his problem was
looking you right in the face... no?

No. Without complete code that has a chance of demonstrating his
problem, why waste my time?
Um... whilst you do have a point that the OP should have displayed complete
code, Mark B is correct that this particular error was staring you in the
face.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Aug 6 '08 #12
On Tue, 5 Aug 2008 13:19:39 -0700 (PDT), ssecorp
<ci**********@gmail.comwrote:
>char* reverse(char* str) {
int length = strlen(str);
char* acc[length];
int i;
for (i=0; i<=length-1; i++){
acc[length-1-i] = str[i];
Due to what is probably the wrong definition of acc, this statement
contains a constraint violation and the compiler must issue a
diagnostic for it. Did yours? If so, why did you ignore it? If not,
either up the warning level or upgrade to a competent compiler.
}
return acc;
}

How do I then print a string and not decimals? If I add printf inside
the for loop it prints decimals. they are reversed so it works but I
want to prin chars.
You need to tell us what code you executed and how the result differed
from what you want. The fact that you used printf is not sufficient.
Show us the exact code.

--
Remove del for email
Aug 6 '08 #13
Default User wrote:
Richard Heathfield wrote:
>Default User said:
Mark B [Diputsur] wrote:
"Default User" <de***********@yahoo.comwrote in message
news:6f************@mid.individual.net...

char* acc[length];

Oops!

I most certainly did NOT write that.

Right - you merely quoted it, and we all do that, obviously.
(Use-mention distinction.)

I fail to understand your point.
I think the point is that the quote markers clearly indicate that you
did not write the "char* acc[length];" line, despite "Mark B
[Diputsur]" deleting the correct attribution line and retaining the
wrong one. So it was, strictly speaking, unnecessary for you to respond
to him, since he wasn't quoting you in the first place.

Aug 6 '08 #14

"ssecorp" <ci**********@gmail.comwrote in message
news:55**********************************@m3g2000h sc.googlegroups.com...
char* reverse(char* str) {
int length = strlen(str);
char* acc[length];
int i;
for (i=0; i<=length-1; i++){
acc[length-1-i] = str[i];
}
return acc;
}

How do I then print a string and not decimals? If I add printf inside
the for loop it prints decimals. they are reversed so it works but I
want to prin chars.

I have no idea what you want, but here is something you can look at:
__________________________________________________ ______________
#include <stdio.h>
#include <string.h>
static char*
reverse_in_place(
char* const buf
) {
char* spos = buf;
char* epos = spos + strlen(spos) - 1;
for (; spos < epos; ++spos, --epos) {
char const tmp = *spos;
*spos = *epos;
*epos = tmp;
}
return buf;
}
static void
fprint_without_char(
FILE* const out,
char const* buf,
char const strip
) {
for (; *buf; ++buf) {
if (*buf != strip || strip == '\0') {
fputc(*buf, out);
}
}
}
int main() {
char data1[] = "\nsdoirep tuohtiw - ...1 .rev .gnirts .esrever";
char data2[] = "\nsdoirep htiw - ...1 .rev .gnirts .esrever";
fprint_without_char(stdout, reverse_in_place(data1), '.');
fprint_without_char(stdout, reverse_in_place(data2), '\0');
return 0;
}
__________________________________________________ ______________

You can reverse the strings and get the output to strip out the periods via
the `fprint_without_char()' procedure...

Aug 6 '08 #15

"Chris M. Thomasson" <no@spam.invalidwrote in message
news:ix****************@newsfe06.iad...
[...]
static void
fprint_without_char(
FILE* const out,
char const* buf,
char const strip
) {
for (; *buf; ++buf) {
if (*buf != strip || strip == '\0') {
fputc(*buf, out);
}
}
}
A more "efficient" version of the code above would be:
__________________________________________________ ________________
static void
fprint_without_char(
FILE* const out,
char const* buf,
char const strip
) {
if (strip) {
for (; *buf; ++buf) {
if (*buf != strip) {
fputc(*buf, out);
}
}
} else {
fprintf(out, "%s", buf);
}
}
__________________________________________________ ________________

[...]

Aug 6 '08 #16
Richard Heathfield wrote:
Default User said:
So? You removed the attribution from the person who DID write it

Yes, he did, but...
and said that I did.

...no, he didn't do that, not as far as anyone is concerned who
retains the ability to count quote-markers.
I'm sorry, but that's a crock.


Brian
Aug 6 '08 #17
santosh wrote:
Default User wrote:
Richard Heathfield wrote:
Default User said:
Mark B [Diputsur] wrote:
"Default User" <de***********@yahoo.comwrote in message
news:6f************@mid.individual.net...

char* acc[length];

Oops!

I most certainly did NOT write that.

Right - you merely quoted it, and we all do that, obviously.
(Use-mention distinction.)
I fail to understand your point.

I think the point is that the quote markers clearly indicate that you
did not write the "char* acc[length];" line
I don't believe that quote markers DO adequately indicate that.


Brian
Aug 6 '08 #18

"Default User" <de***********@yahoo.comwrote in message
news:6f************@mid.individual.net...
Richard Heathfield wrote:
>Default User said:
So? You removed the attribution from the person who DID write it

Yes, he did, but...
and said that I did.

...no, he didn't do that, not as far as anyone is concerned who
retains the ability to count quote-markers.

I'm sorry, but that's a crock.
I apologize if my snip insulted you, but IMHO you
did inherit his mistake with your response.
No. Without complete code that has a chance of demonstrating his
problem, why waste my time?
You had complete code which demonstrated his problem.
The line of code he stuck in for debugging purposes when
the function didn't perform properly sidetracks the issue,
why waste your time asking to see it?

Aug 6 '08 #19
Mark B [Diputsur] wrote:
>
"Default User" <de***********@yahoo.comwrote in message
news:6f************@mid.individual.net...
Richard Heathfield wrote:
Default User said:
>So? You removed the attribution from the person who DID write it
>
Yes, he did, but...
>
and said that I did.
>
...no, he didn't do that, not as far as anyone is concerned who
retains the ability to count quote-markers.
I'm sorry, but that's a crock.

I apologize if my snip insulted you,
Learn basic netiquette.
but IMHO you
did inherit his mistake with your response.
Bullshit. I specifically said that I wasn't going to comment because he
didn't provide a complete example.


Brian
Aug 6 '08 #20
"Default User" <de***********@yahoo.comwrites:
Mark B [Diputsur] wrote:
>>
"Default User" <de***********@yahoo.comwrote in message
news:6f************@mid.individual.net...
Richard Heathfield wrote:

Default User said:

So? You removed the attribution from the person who DID write it

Yes, he did, but...

and said that I did.

...no, he didn't do that, not as far as anyone is concerned who
retains the ability to count quote-markers.

I'm sorry, but that's a crock.

I apologize if my snip insulted you,

Learn basic netiquette.
>but IMHO you
did inherit his mistake with your response.

Bullshit. I specifically said that I wasn't going to comment because he
didn't provide a complete example.


Brian
Calm down Bwian. I think you've had your quota of nagging people about
how and what to post today don't you? No wonder Heathfield kicked your
backside about it last year.
Aug 6 '08 #21
"Richard" <rg****@gmail.comwrote in message
news:g7**********@registered.motzarella.org...
"Default User" <de***********@yahoo.comwrites:
>Mark B [Diputsur] wrote:
>>>
"Default User" <de***********@yahoo.comwrote in message
news:6f************@mid.individual.net...
Richard Heathfield wrote:

Default User said:

So? You removed the attribution from the person who DID write it

Yes, he did, but...

and said that I did.

...no, he didn't do that, not as far as anyone is concerned who
retains the ability to count quote-markers.

I'm sorry, but that's a crock.

I apologize if my snip insulted you,

Learn basic netiquette.
>>but IMHO you
did inherit his mistake with your response.

Bullshit. I specifically said that I wasn't going to comment because he
didn't provide a complete example.
[...]
>
Calm down Bwian.
Its Brian right? If so, why misspell his name on purpose? Seems quite odd
indeed...

:^/

I think you've had your quota of nagging people about
how and what to post today don't you? No wonder Heathfield kicked your
backside about it last year.
Aug 7 '08 #22
Chris M. Thomasson wrote:
"Richard" <rg****@gmail.comwrote in message
news:g7**********@registered.motzarella.org...
>"Default User" <de***********@yahoo.comwrites:
<snip>
>Calm down Bwian.

Its Brian right? If so, why misspell his name on purpose? Seems quite
odd indeed...

:^/
If you were concerned enough with getting his name right, presumably,
you'd also be concerned enough to take his oft repeated advice. :-)

Aug 7 '08 #23
"santosh" <sa*********@gmail.comwrote in message
news:g7**********@registered.motzarella.org...
Chris M. Thomasson wrote:
>"Richard" <rg****@gmail.comwrote in message
news:g7**********@registered.motzarella.org...
>>"Default User" <de***********@yahoo.comwrites:

<snip>
>>Calm down Bwian.

Its Brian right? If so, why misspell his name on purpose? Seems quite
odd indeed...

:^/

If you were concerned enough with getting his name right, presumably,
you'd also be concerned enough to take his oft repeated advice. :-)
Ouch.

Aug 7 '08 #24
On 5 Aug, 21:59, "Mark B [Diputsur]" <diput...@gmail.comwrote:
"Default User" <defaultuse...@yahoo.comwrote in message

news:6f************@mid.individual.net...
Mark B [Diputsur] wrote:
"Default User" <defaultuse...@yahoo.comwrote in message
news:6f************@mid.individual.net...
* * char* acc[length];
Oops!
I most certainly did NOT write that.

No, but you quoted it, and rather than looking
at the code and finding the error, you asked for
additional information, while his problem was
looking you right in the face... no?
no not really. Yes the above is probably wrong (hard to
tell as you snip the context out) but I don't think it
addresses the OP's problem he wants to "print string
and not decimals". I suspect his printf() format is wrong.
--
Nick Keighley
Aug 7 '08 #25
On 7 Aug, 11:42, "Chris M. Thomasson" <n...@spam.invalidwrote:
"Richard" <rgr...@gmail.comwrote in message
<snip>
Calm down Bwian.

Its Brian right? If so, why misspell his name on purpose? Seems quite odd
indeed...
<sighbecause he's trying to be annoying. ie. he's a troll (some of
the
time).

Don't Feed The Troll

--
Nick Keighley
Aug 7 '08 #26
"Nick Keighley" <ni******************@hotmail.comwrote in message
news:d6**********************************@a70g2000 hsh.googlegroups.com...
On 7 Aug, 11:42, "Chris M. Thomasson" <n...@spam.invalidwrote:
>"Richard" <rgr...@gmail.comwrote in message

<snip>
Calm down Bwian.

Its Brian right? If so, why misspell his name on purpose? Seems quite odd
indeed...

<sighbecause he's trying to be annoying. ie. he's a troll (some of
the
time).
IMVHO, the non-consistent trolls are the worst kind!

:^|

Don't Feed The Troll
So sorry about that non-sense.

Aug 7 '08 #27
On Aug 7, 2:41 pm, Nick Keighley <nick_keighley_nos...@hotmail.com>
wrote:
On 7 Aug, 11:42, "Chris M. Thomasson" <n...@spam.invalidwrote:
some troll <rgr...@gmail.comwrote in message

<snip>
Calm down Bwian.
Its Brian right? If so, why misspell his name on purpose? Seems quite odd
indeed...

<sighbecause he's trying to be annoying. ie. he's a troll (some of
the
time).
Some of the time? He's always trolling.
Aug 7 '08 #28
"Chris M. Thomasson" <no@spam.invalidwrote in message
news:uB******************@newsfe08.iad...
"Nick Keighley" <ni******************@hotmail.comwrote in message
news:d6**********************************@a70g2000 hsh.googlegroups.com...
>On 7 Aug, 11:42, "Chris M. Thomasson" <n...@spam.invalidwrote:
>>"Richard" <rgr...@gmail.comwrote in message

<snip>
>Calm down Bwian.

Its Brian right? If so, why misspell his name on purpose? Seems quite
odd
indeed...

<sighbecause he's trying to be annoying. ie. he's a troll (some of
the
time).

IMVHO, the non-consistent trolls are the worst kind!

:^|

>Don't Feed The Troll
Okay. I have feed him enough. I will not reply to him unless its about C
programming. He called me a nazi and pissed me off real good; I don't want
to end up in thousands of killfiles by arguing with him any more than I
already have!

So sorry about that non-sense.
;^(...

Aug 7 '08 #29
Nick Keighley wrote:
On 5 Aug, 21:59, "Mark B [Diputsur]" <diput...@gmail.comwrote:
"Default User" <defaultuse...@yahoo.comwrote in message
No, but you quoted it, and rather than looking
at the code and finding the error, you asked for
additional information, while his problem was
looking you right in the face... no?

no not really. Yes the above is probably wrong (hard to
tell as you snip the context out) but I don't think it
addresses the OP's problem he wants to "print string
and not decimals". I suspect his printf() format is wrong.
And as he hadn't posted a version of the program with a printf()
originally, it didn't seem fruitful to comment on what had been posted.
Hence a request to post the real code. That should have been
unremarkable.


Brian
Aug 7 '08 #30

"Nick Keighley" <ni******************@hotmail.comwrote in message
news:1d**********************************@26g2000h sk.googlegroups.com...
On 5 Aug, 21:59, "Mark B [Diputsur]" <diput...@gmail.comwrote:
>"Default User" <defaultuse...@yahoo.comwrote in message

news:6f************@mid.individual.net...
Mark B [Diputsur] wrote:
>"Default User" <defaultuse...@yahoo.comwrote in message
news:6f************@mid.individual.net...
>char* acc[length];
>Oops!
I most certainly did NOT write that.

No, but you quoted it, and rather than looking
at the code and finding the error, you asked for
additional information, while his problem was
looking you right in the face... no?

no not really.
Yes sir, really.
>Yes the above is probably wrong (hard to
tell as you snip the context out)
It wasn't hard to tell when the thread only had
2 posts on it, much has happened since though.
but I don't think it
addresses the OP's problem he wants to "print string
and not decimals". I suspect his printf() format is wrong.
Fairly obvious that the printf() statement was inserted for
debugging purposes and does not belong in the completed
code.

--

Is this really what CLC has turned into?
I see more than a few familiar names (surprised by the
lack of Dan Pop though, is he still alive and well?)
but there seems to be an abundant number of trolls here
as well. That's a shame.
Aug 7 '08 #31
Mark B [Diputsur] wrote:

<snip>
Is this really what CLC has turned into?
Frankly there more debates on topicality than there should be, but I
don't see any resolution, as different participants hold entrenched
views.

Personally I only object to repeated off-topic posts even after the
concerned poster has been told of the presence of better groups to
serve his purpose. Newbies posting off-topic questions are natural,
since they cannot be expected to know the topicality constraints of
this group even before their first post.

However, there are some here who object to *any* redirection, no matter
how off-topic the post. IIRC one of the so-called trolls even wanted to
deliberately discuss hardware issues here.
[ ... ] there seems to be an abundant number of trolls here
as well. That's a shame.
Well I count all of them on the fingers of one hand. Not that much
really.

Aug 7 '08 #32
Nick Keighley wrote:
On 7 Aug, 11:42, "Chris M. Thomasson" <n...@spam.invalidwrote:
>"Richard" <rgr...@gmail.comwrote in message
>>Calm down Bwian.
Its Brian right? If so, why misspell his name on purpose? Seems quite odd
indeed...

<sighbecause he's trying to be annoying. ie. he's a troll (some of
the
time).
What is this "some of the time"? There are precious few folks in my
killfile; it takes a consistent history of trolling to get there. He's
definitely there.
Aug 7 '08 #33
Mark B [Diputsur] wrote:
>
"Nick Keighley" <ni******************@hotmail.comwrote in message
news:1d**********************************@26g2000h sk.googlegroups.com.
but I don't think it
addresses the OP's problem he wants to "print string
and not decimals". I suspect his printf() format is wrong.

Fairly obvious that the printf() statement was inserted for
debugging purposes and does not belong in the completed
code.
Except that it formed the basis of what he asked. At any rate, it was
clear he was asking about a different program than the one he posted.
So I didn't waste my time on it, anymore than a mechanic takes a look
as similar car to the one that's malfunctioning.


Brian
Aug 7 '08 #34
CBFalconer wrote:

And it is even attracting comment from the twin trolls Richard and
Twink, thus quadrupling the length of the useless thread. If you
keep it up you will probably also attract McCormack. At least they
are plonkable, but we don't really want to plonk you two.

What the hell do I care what trolls think or do? We should refrain from
posting because the trolls might respond? If you choose not to plonk
trolls, that's not exactly my responsibility.

Brian
Aug 7 '08 #35
On Aug 6, 8:19 am, ssecorp <circularf...@gmail.comwrote:
char* reverse(char* str) {
int length = strlen(str);
char* acc[length];
int i;
for (i=0; i<=length-1; i++){
acc[length-1-i] = str[i];
}
return acc;

}
Something nobody has mentioned yet (despite
there being 47 replies already) - you try to
return the address of a local array, that
will no longer exist once the function returns.

If you want to return a string then you will
have to be more careful about allocating
memory for it.
Aug 8 '08 #36
On Aug 7, 9:26*pm, Old Wolf <oldw...@inspire.net.nzwrote:
On Aug 6, 8:19 am, ssecorp <circularf...@gmail.comwrote:
char* reverse(char* str) {
* * *int length = strlen(str);
* * *char* acc[length];
* * *int i;
* * *for (i=0; i<=length-1; i++){
* * * * *acc[length-1-i] = str[i];
* * *}
* * *return acc;
}

Something nobody has mentioned yet (despite
there being 47 replies already) - you try to
return the address of a local array, that
will no longer exist once the function returns.

If you want to return a string then you will
have to be more careful about allocating
memory for it.
Hey! I know you!

Might want to read a few of those 47 replies...
it's been mentioned numerous times ;-)
Aug 8 '08 #37
On Aug 8, 2:16 pm, "Mark B (Diputsur)" <diput...@gmail.comwrote:
Hey! I know you!

Might want to read a few of those 47 replies...
it's been mentioned numerous times ;-)
True, I skipped over half of the thread
where it looked like everybody was
bickering about irrelevant crap.
Aug 8 '08 #38
Mark B [Diputsur] wrote:
>
"Default User" <de***********@yahoo.comwrote in message
news:6g************@mid.individual.net...
Mark B [Diputsur] wrote:
>
"Nick Keighley" <ni******************@hotmail.comwrote in message
news:1d**********************************@26g2000h sk.googlegroups.
com.
>but I don't think it
addresses the OP's problem he wants to "print string
and not decimals". I suspect his printf() format is wrong.
>
Fairly obvious that the printf() statement was inserted for
debugging purposes and does not belong in the completed
code.
Except that it formed the basis of what he asked. At any rate, it
was clear he was asking about a different program than the one he
posted. So I didn't waste my time on it, anymore than a mechanic
takes a look as similar car to the one that's malfunctioning.

OMFG, you don't let up!
Just persistent that way! It helps being right and all.

Weren't you supposed to be "done with me"?

Brian
Aug 8 '08 #39

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

59
by: Raymond Hettinger | last post by:
Please comment on the new PEP for reverse iteration methods. Basically, the idea looks like this: for i in xrange(10).iter_backwards(): # 9,8,7,6,5,4,3,2,1,0 <do something with i> The...
13
by: Brad Tilley | last post by:
A friend of mine wrote an algorithm that generates strings. He says that it's impossible to figure out exactly how the algorithm works. That may be true, but I think if I had enough sample strings...
8
by: vijay | last post by:
Hello, As the subject suggests, I need to print the string in the reverse order. I made the following program: # include<stdio.h> struct llnode { char *info;
10
by: aatish19 | last post by:
1: Write a program that asks the user to input an integer value and print it in a reverse order Sample Output Enter any number 65564 Reverse of 65564 is 46556 2: Write a program that takes a...
41
by: rick | last post by:
Why can't Python have a reverse() function/method like Ruby? Python: x = 'a_string' # Reverse the string print x Ruby: x = 'a_string' # Reverse the string
7
by: analoveu | last post by:
I wanna print the following shape 1 121 12321 1234321 12321 121 1
3
by: analoveu | last post by:
I have a problem with using the reverse method any one give me an exmample or correct my error inside this code String p=""; for(int x=0 ; x<=3 ; x++) p+=x; System.out.print(p); String...
7
by: Dag Sunde | last post by:
I want to use the format-number function to output a number with a specific number of decimals, based on the content of a node... Is there any smart way to generate differnet strings based on a...
12
by: nembo kid | last post by:
How I (recursive) can reverse and print a string (as simple as possible)? I tried with the following code, but it doesn't work. Thanks in advance to everbody. /* Code starts here */ ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.