[prog] Re: learning c
Alice Moomlyn
alice_moomlyn at yahoo.com
Mon Mar 29 03:17:17 EST 2004
<alice>
Thankyou for replying!
</alice>
<almut>
BTW, upon first running your orignal version, I got,
for example
Enter a string of any length:
Alice Moomlyn
This is the string you entered:
Alice Moomlyn
Reversed using array notation:
ylmooM ecilA
Reversed using pointer notation:
ylmooM ecilA
(Note that in the reversed string, the 'n' from
Moomlyn is missing...)
</almut>
<alice>
Whoops!
Just goes to show that I wasn't doing proper testing!
At first the 'reverse' was working but the reading in
of long strings wasn't, so I kinda went around
changing things at random (I know that's not what
you're supposed to do :P) until the input was working,
and then I did all my tests on really long strings of
largely repetitive characters, like this:
"ddddddddddddddddddddddddddddddddddddddkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkfffffffffffffffffffffffffffffffffffffffjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj"
so that must be why I didn't realize that the last
letter was being chopped off :P
Anyway, I think I've fixed it now.
</alice>
<almut>
> A purely syntactic issue:
>
> Only statements need to be terminated by semicolons,
> not the control
> structure elements like the {}-blocks used for
> grouping statements
> (as usually used in combination with if/else, while,
> for, function
> definitions, etc.). I.e. it suffices to write
>
> while (cond) {
> statement;
> statement;
> }
> nextstatement;
>
</almut>
<alice>
Ahh...yes. I think I'd kind of half-noticed that the
compiler didn't report errors when I forgot the ;
after code blocks but was still putting them in to be
on the safe side. Thanks for pointing that out!
</alice>
<almut>
This is a very neat program for locating all sorts of
memory-related
errors, like accessing undefined variables, memory
outside of allocated
buffers, and much more. To be able to do that, it
runs the program in
a CPU emulated by software. Sounds complex? It is, but
it works rather
well. More info at http://valgrind.kde.org/
If you want to keep programming in C(++), do yourself
a real favor - go
and get it now!
</almut>
<alice>
Will do.
</alice>
<almut>
Always come
up with test cases which are maximally "nasty" to the
program, i.e. use
sizes exactly matching internal buffersizes (or
multiples thereof), or
buffersize-/+1, or any other magic value which is
brought into
existence by way of the various constants you put in
your code -- you
get the idea...
</almut>
<alice>
I think so...
</alice>
<almut>
P.S. a final meta comment: in order to get more
feedback here (and
elsewhere), try to pose _specific_ questions, or point
at certain
errors you encountered. For example, you could have
asked "why does
the first character of the reversed string get lost?".
I bet you'd
have gotten at least 5 responses on that one. Very
general requests
for feedback tend to offer a low incentive for the
time-stressed geek.
At least _I_ feel more inclined to respond, when
there's something
catchy, and it looks like I can find out and answer it
in a reasonable
amount of time. Could be that I'm not the only chick
feeling that way.
</almut>
<alice>
To be honest I hadn't even noticed that the last
letter was being chopped off :P I was more looking for
general feedback on coding style etc...
I want to get off to a good start with c, not fall
into bad habits right from the beginning.
I've rewritten the whole thing, breaking it up into 4
files:
1. STRio.h (string input-output header)
http://rafb.net/paste/results/R1575136.html
2. STRio.c (string input-output implementation)
http://rafb.net/paste/results/Fqx42015.html
3. STRmanip.h (string manipulation header)
http://rafb.net/paste/results/m3064945.html
4. STRmanip.c (string manipulation implementation)
http://rafb.net/paste/results/Ux460433.html
If anybody has time to take another look at it and
make any additional comments, that would be great. But
if you're all to busy, that's okay. I understand.
</alice>
=====
"the only way to learn how to be clever is to say stupid things" - anon
__________________________________
Do you Yahoo!?
Yahoo! Finance Tax Center - File online. File on time.
http://taxes.yahoo.com/filing.html
More information about the Programming
mailing list