Shae Tan <[EMAIL PROTECTED]> writes:

> Hello everybody,
> Can you help me with this (I know there are very good C programmers here):

I'm not a C programmer (yet,) but with Emacs' Info-mode handy, there's
no telling =)...

> FILE *stream;
>       int inputArraySize;
>       int *inputLengthArray;
>       int *inputDirectionArray;
>       
>       stream = fopen("db.txt","rt");
>       
>       fscanf(stream, "%d\n", &inputArraySize);
>
> // this is line 24    
>       inputLengthArray = calloc(inputArraySize, sizeof(int));
> // this is line 25
>       inputDirectionArray = calloc(inputArraySize, sizeof(int));
>       
>       fclose(stream);
>
> The compiler (GCC) reports the following warnings:
> 24: warning: assignment makes pointer from integer without a cast
> 25: warning: assignment makes pointer from integer without a cast
>
> What is wrong with my code?

Info <[EMAIL PROTECTED]> writes:

> The function `calloc' allocates memory and clears it to zero.  It is
> declared in `stdlib.h'.

>  - Function: void * calloc (size_t COUNT, size_t ELTSIZE)
>      This function allocates a block long enough to contain a vector of
>      COUNT elements, each of size ELTSIZE.  Its contents are cleared to
>      zero before `calloc' returns.

>    You could define `calloc' as follows:

>      void *
>      calloc (size_t count, size_t eltsize)
>      {
>        size_t size = count * eltsize;
>        void *value = malloc (size);
>        if (value != 0)
>          memset (value, 0, size);
>        return value;
>      }

>    But in general, it is not guaranteed that `calloc' calls `malloc'
> internally.  Therefore, if an application provides its own
> `malloc'/`realloc'/`free' outside the C library, it should always
> define `calloc', too.

From what it looks, there's a type mismatch in your code, since
inputLengthArray and inputDirectionArray are pointers to ints, while the
standard definition of calloc() returns a pointer to void. Thus, you
might need to define your own calloc() and the related functions as
well. Another might be to redefine your arrays as void*, but I might be
wrong...

But please do take that with a grain of salt =). I myself have been
learning C for quite a while, though I'm familiar with its contructs
common to other languages. I haven't found too much use for it in my
projects, though, as I'm too busy trying out Emacs Lisp :D

HTH

-- 
ZAK B. ELEP     <[EMAIL PROTECTED]>     --      <http://zakame.spunge.org>
1024D/FA53851D          1486 7957 454D E529 E4F1  F75E 5787 B1FD FA53 851D
--  Running Debian GNU+Linux testing/unstable. GnuPG signed mail preferred.

Attachment: pgp27YZHkBPgD.pgp
Description: PGP signature

--
Philippine Linux Users' Group (PLUG) Mailing List
[email protected] (#PLUG @ irc.free.net.ph)
Official Website: http://plug.linux.org.ph
Searchable Archives: http://marc.free.net.ph
.
To leave, go to http://lists.q-linux.com/mailman/listinfo/plug
.
Are you a Linux newbie? To join the newbie list, go to
http://lists.q-linux.com/mailman/listinfo/ph-linux-newbie

Reply via email to