sgi said:
Hello Vladimir,
well i am new to C language and newsgroups
too. this c lang group is my first group and urs was the first post i
saw, but i was baffled by this new and strange syntax.
A few notes to begin with:
1) Don't top-post. Your reply belongs below, or interspersed with the
article you're replying to.
2) Do not snip attribution lines (the ones that say who said what, like
"sgi wrote:" above). They are important.
3) You seem to be using Google, and trying to do it properly. However,
do not click "Reply to author" as this send an e-mail, rather than
posting a reply to the newsgroup. There are two problems with this.
First, many people do not reveal their real e-mail addresses, so it's
likely they'll never see your reply. Second, unless there's a very
good reason for it, discussions should be in the open so all in the
newsgroup can see, learn, and correct.
I have corrected all three here:
Vladimir S. Oka opined:
array[*track] = malloc(1);
can u do things like this? wat is the index of the array? isn't the *
symbol used with pointers? how can a pointer be an index of an array?
or is it the value pointed to by the pointer that is the index of the
array? can u help me out in understanding this puzzle?
The construct *<pointer variable> is de-referencing the pointer, i.e.
it yields the value pointed to. Thus, in the line above, `*track`
reads the `int` value pointer `track` points to, an that value is then
used as index into the `array`.
I have used `malloc(1)` since I know `array` is an array of `char` and
size of `char` in C is always 1. It would have been much better had I
done something like:
array[*track] = malloc( sizeof array[*track] );
This guarantees that the above line will work regardless of how you
change the type of `array` elements.
As a side not: do not ever cast the value returned by `malloc()`. It is
not necessary, and it will only hide the problem if you forget to
#include said:
that'll be a great help and encouragement to me. And also, i'd like
to know u better. I need some friend out here to help me out in this
confusing world of newsgroups etc. can u be my guide here?
For guidance on this particular group, it's sufficient to read the link
in my sig (and all links contained therein), and follow the
recommendations. There are also good sources on the Internet on the
general culture of Usenet (although groups differ). General advice is
to lurk (i.e. follow the traffic) of any group you'd like to
participate in for at least couple of months to get a feel of the
local customs. Google Groups can help here if you want to compress a
couple of months into couple of hours.
The above is almost certain to be enough guidance (provided you add a
good dose of common sense). Also, topicality and netiquette should be
on-topic in all groups (including this one).
--
But what can you do with it? -- ubiquitous cry from Linux-user
partner.
(Submitted by Andy Pearce, (e-mail address removed))
<
http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>