Why it doesn't work?

O

Olaf \El Blanco\

#include <stdio.h>

// If char *frase="Andrew" I want *frase="werdnA" with THIS for...

int main()
{
int start, finish;
char aux;
char *phrase="Andrew... is listening to Dimmu Borgir...";
finish=strlen(phrase)-1;

for (start=0; start<finish; start++, finish--) {
/* Changing... */
aux= *(phrase+start);
*(phrase + start) = *(phrase + finish);
*(phrase + finish) = aux;
}
return 0;
}
 
W

Walter Roberson

// If char *frase="Andrew" I want *frase="werdnA" with THIS for...

You don't print out the result of your algorithm, so you can't
tell whether it worked or not.
 
O

Olaf \El Blanco\

:) This is not the whole program...


Walter Roberson said:
You don't print out the result of your algorithm, so you can't
tell whether it worked or not.
 
W

Walter Roberson

Walter Roberson said:
:) This is not the whole program...

Well then post an example that shows clearly the code for the example
and describe the result you are seeing.

Because there are no side effects in your code, compilers are allowed
to optimize it out completely (except for the return code.)

Oh, and fix your declaration of main, and figure out how to
declare strlen().

For what it's worth, the output I got after putting in a puts() was

....rigroB ummiD ot gninetsil si ...werdnA
 
O

Olaf \El Blanco\

Well then post an example that shows clearly the code for the example
and describe the result you are seeing.

Because there are no side effects in your code, compilers are allowed
to optimize it out completely (except for the return code.)

I use gcc and is infinite... No result.
 
S

santosh

Olaf said:
:) This is not the whole program...

Please refrain from top-posting and be more clear about your question.
What's the point of answering to Walter's comment with a reply like the
above, preceded by a smiley? Are you intentionally trying to be
obnoxious?

Please read the material at the following URLs *before* posting here
again, you if want the regulars to continue to take you seriously.

<http://cfaj.freeshell.org/google/>
<http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>
<http://www.safalra.com/special/googlegroupsreply/>
 
O

Olaf \El Blanco\

Of course I don't want to be obnoxius! I am with the Babylon translation!!
My english isn't good!

I just execute my program with gcc and is infinite...
I suppose that it wasn't necesary to put more lines (printf lines) and I
understand that like a joke...

I'm sorry again.
 
D

Default User

Olaf "El Blanco" wrote:

Please don't top-post. Your reply belongs following or intermixed with
properly trimmed quotes.
:) This is not the whole program...

Why not? How can we duplicate your problem if you don't show us
everything? If the program is too large to post, cut it down to a
smaller example that demonstrates the problem. Often you'll find the
problen on your own while doing that. Then tell exactly what you see.
"Doesn't work" doesn't work.



Brian
 
S

stathis gotsis

Olaf "El Blanco" said:
#include <stdio.h>

Add:
#include said:
// If char *frase="Andrew" I want *frase="werdnA" with THIS for...

int main()
{
int start, finish;
char aux;
char *phrase="Andrew... is listening to Dimmu Borgir...";

phrase points to a string literal, which you try to modify later on. That is
not allowed. Try:

char phrase[]="Andrew... is listening to Dimmu Borgir...";
 
S

santosh

Olaf said:
Of course I don't want to be obnoxius! I am with the Babylon translation!!
My english isn't good!

I just execute my program with gcc and is infinite...

Post the *full* source of your program, (copy and paste, don't retype),
if you wan't more help.
I suppose that it wasn't necesary to put more lines (printf lines) and I
understand that like a joke...

I'm sorry again.

I wonder if you shouldn't first learn English better before posting to
this group, as you seem to have severe langauge, (and hence
comprehension), problems. Alternatively, you could post is a group in
your native tongue.
 
S

santosh

Olaf said:
#include <stdio.h>

// If char *frase="Andrew" I want *frase="werdnA" with THIS for...
.... snip code ...

Search this group with the term 'string reverse'. There was a
discussion quite recently on this subject and many regulars presented
their solutions.
 
C

CBFalconer

santosh said:
Post the *full* source of your program, (copy and paste, don't
retype), if you wan't more help.


I wonder if you shouldn't first learn English better before
posting to this group, as you seem to have severe langauge,
(and hence comprehension), problems. Alternatively, you could
post is a group in your native tongue.

His English is obviously good enough to post here and probably much
better than my (or your) knowledge of his language, however his
understanding of such things as snipping, top-posting, etc. is
obviously lacking. Explanations will probably go further than
yelling.

(Directed to Olaf)
Re top-posting, your answer belongs after, or possibly intermixed
with, the quoted material to which you reply, after snipping out
anything not germane to your answer.

Reading the following URLs may help.

http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.greenend.org.uk/rjk/2000/06/14/quoting.html
http://www.i-hate-computers.demon.co.uk/
http://web.ukonline.co.uk/g.mccaughan/g/remarks/uquote.html

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>
 
P

Peter Shaggy Haywood

Groovy hepcat Default User was jivin' on 27 Mar 2006 22:31:59 GMT in
comp.lang.c.
Re: Why it doesn't work?'s a cool scene! Dig it!
Why not? How can we duplicate your problem if you don't show us

The code he posted was enough to compile and show the problem, so he
didn't need to post any more. (Of course, I'm assuming the obvious
problem in the code he posted was the one he meant to ask about.) You
(rightly) say below that he should cut down the code, if it's too
large, to something that still compiles and shows the problem. Well,
duh! :)
everything? If the program is too large to post, cut it down to a
smaller example that demonstrates the problem. Often you'll find the

That's exactly what he did.
problen on your own while doing that. Then tell exactly what you see.
"Doesn't work" doesn't work.

Absolutely! Olaf, you should have said what the code was supposed to
do and what it actually does, including verbatim all diagnostic output
emitted by your compiler and your program, if any. This should all be
clear, concise and to the point. When you get sick you don't go to the
doctor and say "I feel sick," then leave. You describe the symptoms so
he can make a proper diagnosis. Well, we need the same thing here to
diagnose problems in your code.

--

Dig the even newer still, yet more improved, sig!

http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?
 
O

Olaf \El Blanco\

Absolutely! Olaf, you should have said what the code was supposed to
do and what it actually does, including verbatim all diagnostic output
emitted by your compiler and your program, if any. This should all be
clear, concise and to the point. When you get sick you don't go to the
doctor and say "I feel sick," then leave. You describe the symptoms so
he can make a proper diagnosis. Well, we need the same thing here to
diagnose problems in your code.

Ok, thank you... I know for the next.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,176
Messages
2,570,947
Members
47,501
Latest member
Ledmyplace

Latest Threads

Top