Programming error - arrays overwriting.

Programming error - arrays overwriting.

Post by UnixMyLo » Fri, 10 May 1996 04:00:00



Ok, I will give this a try. Declare the arrays as x[5] rather than *x. On
some
machines these are two different animals. I have seen this when in one
source file the array is declared as:

int x[5];

And in the second source file it is declared as:

extern int *x;

Core dumps every time. Of course, this will be the first time that it has
happen from as a parameter to a function rather than the extern variable.
Anyway, I have been fortunate (or may not) to write programs
that need to run on three or four different platforms. You learn alot
about how
portable a programming language really is. Tip of the day: Try to keep
your
declarations as consistant as possible. You never know what the next
compiler
is going to do. And yes some of the machines have ascii C while some are
the old K&R and I still have strange little problems come up from time to
time.

Jane G
Maryland

 
 
 

Programming error - arrays overwriting.

Post by Andrew Gier » Fri, 10 May 1996 04:00:00




Quote:>I'm sure its just me screwing up pointers and arrays.

Yes. Misunderstood array bounds - newbie C programming error #1  :-)

Quote:>void reset_cube(int *x, int *y, int *z, int *ex, int *wy, int *zd, int *FBxyz)
>{
>  int i;

>  for(i=0; i<NUMPIECES; i++){  /* reset the cube to solved/defined config. */
>    x[i] = ex[i];
>    y[i] = wy[i];
>    z[i] = zd[i];
>  } /* end for 0 to NUMPIECES */
>  FBxyz[0] = 'F';
>  FBxyz[1] = 'R';
>  FBxyz[2] = 'U';
>  FBxyz[3] = -'B';
>  FBxyz[4] = -'L';
>  FBxyz[5] = -'D';
>} /* end reset_cube */

>Am I passing my pointers to the function wrong ?
>Did I declare the wrong types .. doubles, longs, shorts and that kind of
>stuff ?
>I used "int FBxyz[5];" and "int x[NUMPIECES];" and so on for y and z.

should be  'int FBxyz[6];'.

Array size in declaraction is the number of elements to allocate, so
the valid subscript range for an array declared foo[N] is 0..N-1

Quote:>I know this isn't exactly the right newsgroup, please feel free
>to direct me to the right one.

comp.lang.c or comp.lang.c.moderated

Quote:>Thanks for any pointers (heh) and flames.

>PeterJordan


"How is this place run - is it an anarchy?"
"No, I wouldn't say so; it is not that well organised..."

 
 
 

Programming error - arrays overwriting.

Post by Peter Jord » Fri, 10 May 1996 04:00:00



Quote:>>I'm sure its just me screwing up pointers and arrays.
>Yes. Misunderstood array bounds - newbie C programming error #1  :-)
>>I used "int FBxyz[5];" and "int x[NUMPIECES];" and so on for y and z.
>should be  'int FBxyz[6];'.

That did it.

Thanks guys.
Since I already released this program into the public domain
here it is again :

http://www.ualberta.ca/~pjordan/web_cube_source.html

I hope someone gets some use out of it.
(please email me if you do)

PeterJordan

 
 
 

1. Disk Overwrite program

Are there any freely available programs that will overwrite
a disk with all 0's, then all 1's for a user specified number of times?
I have heard of something called diskko, but archie.unl.edu doesn't
seem to know about it.  Anything that runs on a PC or Sun or
MacIntosh would be OK.  Thanks!

Tim Lines
My employers are too responsible to
allow ME to speak for them.

2. Linux Router!!

3. 3x Overwrite Program

4. SSA and downlevelling AIX

5. 'Out of Memory error' after overwriting /etc/fstab

6. Taking over a disk partition

7. /bsd: arp overwritten error and dhclient: send_fallback: No route to host

8. How do I uninstall AccelX CDE, I broke it :-(

9. "text file busy" error when trying to overwrite pages

10. Finding array indexes from array values

11. scraid array how long to build arrays

12. help to array notseeing LUNs on 2nd and 3rd disk array

13. arrays creating new arrays in dtksh