Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

farmerdoug

macrumors 6502a
Original poster
Sep 16, 2008
541
0
Code:
float *y, *ys;
int j;
if ((ys = (float *)calloc(points*points,sizeof(float))) == NULL)
		printf("ys\n");
if ((ys1 = (float *)calloc(points,sizeof(float))) == NULL)
		printf("ys1\n");
...
memcpy[ys[i*points],ys1,j*sizeof(float)];  // line  220

2dspline.c:220: error: subscripted value is neither array nor pointer

At least I remembered (evidentually) to declare and calloc ys as a *float not **float.
 
Your memcpy is using [] instead of () to surround the arguments to the function.

Also you declare y and ys but then use ys and ys1.
 
ys[i*points] indexes ys at i*points, since ys is a pointer to floats that would be a float.

You can't memcpy to a float.

That explains the error.

Now, for what you actually want to do: I have no clue.

-edit-

Oh, or what Mr. Duncan said there.
 
pointers

thanks, I don' t think there is enough coffee in the world to wake me up. Also, the variables are defined somewhere. At least I got that right.
 
Chaos

That might have something to do with it. There are work around, like loops for assigning things one at a time. Also assigning pointers
p[0] = *y[0] or something similar.
 
memcpy documentation says:

Code:
void *memcpy(void *s1, const void *s2, size_t n);

The memcpy() function copies n bytes from the object pointed to by s2 into the object pointed to by s1.

So if s1 is a float rather than a pointer then it won't work.
 
this compiled

Code:
float **ys, *ys1;


if ((ys = (float *)calloc(points,sizeof(float))) == NULL)
		printf("ys\n");
		
if ((ys1 = (float *)calloc(points,sizeof(float))) == NULL)
		printf("ys1\n");

	for (i = 0; i < points; i ++)
		{
	
		if ((ys[i] = (float *)calloc(points,sizeof(float))) == NULL)
			printf("ys[i]\n");
		}

	 memcpy(ys[i], ys1, j*sizeof(float));

[code]

I used the **ys, not to make memcpy work, but as required by Numerical Recipies in C.
 
That might have something to do with it. There are work around, like loops for assigning things one at a time. Also assigning pointers
p[0] = *y[0] or something similar.

That copies the content of what y[0] is pointing to to p[0], This only works if y is a pointer to an array of pointers.

When I say 'works' I mean that it does what you mean it to do, it might still compile otherwise but it most certainly won't do what you expect :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.