[Sussex] C programming help

Captain Redbeard hairy.one at virgin.net
Mon Apr 25 19:15:46 UTC 2005


Hi all,

I've just spent the last 48 hours (I think I remember getting some sleep 
somewhere) trying to get a C program that I'm coding to work.  I'm not a 
trained programmer, just amateur stuff, library books, things like that 
but the program uses some fairly advanced concepts like function 
pointers, arrays of structures, etc.  The program (a miniature ecosystem 
simulator) has pretty much all of the functionality coded into it that I 
want however I keep running into run-time crashes like "segmentation 
faults" and more bafflingly "*** glibc detected *** double free or 
corrupted (!prev):" and variations on this.  I suspect that the problem 
comes from mishandling pointers and malloc()/free() statements, 
traceable probably to a deeper misunderstanding of how memory allocation 
works in C.  Does anybody know of any good forums where learner/newbie 
programmers can get help with this sort of thing?  None of the 
tutorials/books I found delve deeply enough into the kind of concepts 
mentioned enough to be of use and Googling for the error messages only 
gives errors in specific applications without explaining exactly what 
"*** glibc detected ***" actually means.  On the other hand if there are 
any C programmers on this mailing list who would be willing to help me 
out then let me know and I can post some short example programs here.  
I've been working on the program every evening for about two weeks now 
and have a LOT of backlogged questions.

Here is an example of what I am running into.  As far as I know the 
following program should be syntactically correct.  It compiles OK but 
when I run it I get a "Segmentation fault" error.  Why?

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

// Set up a coordinate structure
struct Coords
{
  int X;
  int Y;
};

// Set up an array of structures (???)
struct Coords **CoordArray;

int main()
{
  // Initialises the first element of the array
  CoordArray[0] = malloc (sizeof (struct Coords));

  return 0;
}
========================================

Note: if it makes any difference, I'm using GCC version 3.3.4 under 
Slackware 10.2 using the command "gcc -Wall -o malloctest malloc.c".

Any ideas anyone?



Captain Redbeard.


---------------------------------------------------------------------------------- 

Generic Internet Technical Services (GITS) plc e-mail disclaimer.

This e-mail and any files transmitted with it are confidential and may
be protected by legal privilege.  If you are not the intended recipient
we would like to know how the hell you got this bloody password.  Own up
and get out of this system right now before we really get angry.  This 
e-mail
has been scanned for malicious content, known viruses, spyware, material of
a slanderous nature, content that expresses any kind of natter or 
disaffection
with the management of GITS plc, pornographic content, or material that
could be potentially highly embarrassing to any GITS plc employees.  Any
such matter has been removed, with the exception of the pornographic
material which is automatically passed on to the Board of Directors and
potentially embarrassing data which is sent on a broad circular mailing 
to all
GITS plc employees.  However the Internet is inherently insecure and 
full of
pornographic/personally embarrassing material so GITS plc cannot accept
any liability for the integrity or cleanliness of this message or its
attachments or responsibility for any loss, damage or embarrassment
caused thereby, actually GITS plc has never taken any kind of
responsibility for anything, ever, even if it clearly WAS our fault..
No employee or agent of GITS plc is authorized to conclude any binding
agreement on behalf of GITS plc or any related company by e-mail, or by
phone, or by letter, or... come to think of it no employee of GITS plc
is authorized to enter into any kind of binding agreement with anybody,
ever, for whatever reason, by whatever means, especially agreements of a
pornographic nature - shows how much we trust these idiots, really.  The
opinions expressed in this e-mail are solely the opinions of the author
of the e-mail - unless of course he/she is simply mouthing off the words
of an opinion leader, or someone they respect, or someone they like the
ideas of, or even someone they're desperately trying to get into bed
with and take pornographic pictures of and think that by pretending to
share their viewpoints that their chances of achieving this outcome will
be greatly increased - and are not the opinions of GITS plc itself,
which has no official opinion - except for the opinion that all of its
employees are mindless, sex-starved idiots who are too stupid to deserve
to have an opinion of their own really.  All e-mails sent and received
by GITS plc are monitored to ensure compliance with the company's
security policy, and to ensure that to ensure that no GITS employee is
spending his whole day downloading porn and trying to get laid.  GITS
plc is an equal opportunities employer, unless you're a Frog, or a
Kraut, or a Wop, in fact none of those daft Eurotrash need bother
applying.
---------------------------------------------------------------------------------- 










More information about the Sussex mailing list