[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Need Orca/C help...
In article <eg58451@pro-scat.cts.com> seane@pro-scat.cts.com (Sean Eller)
writes:
>I'm working on a project that uses arrays and I wanted to clear the array
>to zero after intializing it. So this is the code I was using:
>int array[100] [100];
[rest of code punted]
>It works fine but takes forever. I looked in the manual and it says I can
>use the function calloc to do the same thing and it will clear the memory
>with zeros automatically. My question is: How would I use the above
>example with calloc and then access the array at a later time? I think it
In C, arrays and pointers can be referenced identically. The only difference
is in the declaration and the allocation of space.
To dynamically allocate an array like the above, try this:
int *array;
array = (int *) malloc (sizeof(int)*100000);
To use calloc, simply change the allocation to:
array = (int *) calloc (1,sizeof(int)*100000);
>uses pointers but I'm not sure of how to write or read from the array.
>Before if I wanted to write or read it would simply be this:
>array[5][10] = 1
>or getvalue = array[5][10]
This should still work fine.
>Thanks...
Hope this helps.
>Internet: seane@pro-scat.cts.com
--
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
| James Brookes | Inet: bb252@cleveland.freenet.edu |
|``What, me worry?'' - A. E. Neuman | jamesb@cscihp.ecst.csuchico.edu |
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::