By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,908 Members | 1,321 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,908 IT Pros & Developers. It's quick & easy.

reverse string, how to print string and not decimals?

P: n/a
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
Share this Question
Share on Google+
38 Replies


P: n/a
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

P: n/a

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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

"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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

"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

P: n/a

"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

P: n/a
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

P: n/a
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

P: n/a

"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

P: n/a
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

P: n/a
"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

P: n/a
"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

P: n/a
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

P: n/a
"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

P: n/a
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

P: n/a
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

P: n/a
"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

P: n/a
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

P: n/a
"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

P: n/a
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

P: n/a

"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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.