Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Infinite for loop

$
0
0
Hello guys i am trying to write a code which produces a b-spline points in curve

What i want to do is read the control points from a file and then calculate the curves points.
When i manually enter the control points (as in the comment brackets)the code runs but when i try to read them
from a file it crashes.

I also get a warning warning: format '%f' expects argument of type 'float *', but argument 3 has type 'double' [-Wformat]|
||=== Build finished: 0 errors, 1 warnings (0 minutes, 1 seconds) ===|

Here's my code

int main()
{
    int i;
	int npts,k;
	int p1;

	float b[31];  /* allows for up to 10  control vertices */
	float h[11];  /* allows for up to 10  control vertices */
	float p[103]; /* allows for up to 100 points on curve */

	FILE *splineinput;

	splineinput = fopen("splineinput.txt","r");


    npts = 5;
	k = 5;     /* third order, change for other orders */
	p1 = 35;   /* eleven points on curve */

	  for(i=0;!feof(splineinput);i++)
    {
        fscanf(splineinput,"%f",b[i]);
    }
	for (i=1; i <= npts; i++){
		h[i] = 1.0;
	}

	h[3] = 1;

	for (i = 1; i <= 3*p1; i++){
		p[i] = 0.;
	}


	/*b[1]=0;
	b[2]=0;
	b[3]=1;
	b[4]=1;
	b[5]=2;
	b[6]=1;
	b[7]=2.5;
	b[8]=0;
	b[9]=1;
	b[10]=4;
	b[11]=2;
	b[12]=1;
	b[13]=5;
	b[14]=0;
	b[15]=1;*/

	rbspline(npts,k,p1,b,h,p);

	printf("\nPolygon points\n");

	for (i = 1; i <= 3*npts; i=i+3){
		printf(" %f %f \n",b[i],b[i+1]);
	}

	printf("\nHomogeneous weighting vector is \n");
	for (i = 1; i <= npts; i++){
		printf(" %f ", h[i]);
	}
	printf("\n");


	printf("\nCurve points\n");

	for (i = 1; i <= 3*p1; i=i+3){
		printf(" %f %f \n",p[i],p[i+1]);
	}


    fclose(splineinput);
	return 0;
}



Can you please check it out because i am getting really frustrated...!!!!

Thank you

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>