PROS Array -> File

Hello Vex Community!
In my program, I have an array that is created, and its components are defined by any change in events by the motors (at which its defined to the value of motorGet()) The array is created, and defined correctly, as I can see in the for loop within my code with the printer values (to the LCD) of the motorvalues. However, when exporting the text file created, an array out of bounds error is received in PROS. Is it because fprintf is not made to output to a *FILE stream (it does not mention it in the API.H, so that’s probably the problem).

Thus, what method would be most optimal for a human to read? (I plan to later implement code to read from the file, and reconstruct the same array).

*Note, in the code, I may have included an extra bracket. Not actually included in the program. woops
**If anyone needs the actual file, I am happy to provide. The spacing seems to be really jacked up in the

, though that's *partially* my fault.

[CODE]

void operatorcontrol (){
//do stuff, array initialization.
	int c = 20;
	int x; int y;
	long int starttime = millis();
	int i = 20; // amount of ticks for recording autonomous
	int k = 5;// k is the amount of motors
	int Times*;
	Times[1] = starttime;
	long int rMotor*[k];
	int a = 1;
	rMotor[1][1] = motorGet(1); //StrafeWheel
	rMotor[1][2] = motorGet(2); //Left Side of Drive
	rMotor[1][3] = motorGet(3); // Right Side of Drive
	rMotor[1][4] = motorGet(6); // Left Arm
	rMotor[1][5] = motorGet(7); // Right Arm
while(1){
//opcontrol functions, and array definitions(event based)
				if(a == i){
				x = 0; y =0;
				motorStopAll();
				lcdClear(uart1);
				lcdSetBacklight(uart1, true);
				FILE *rMot;// = "rMot";
				//FILE *Timings;// = "Timings";
				lcdPrint(uart1, 1, "FIN %d", a);
				//fopen("Mot_ArmR", "w");
				//fopen("rMot", "w");
				//fopen("Timings", "w");
				rMot = fopen("rMot", "w");
				//Timings = fopen("Timings", "w");
				int ca;
				for(ca = 1; ca < 20; ca++){
					delay(2000);
					lcdClear(uart1);
					lcdPrint(uart1, 2, "%d , %ld", ca, rMotor[1][ca]);
					//lcdPrint(uart1, 2, "%d , %ld", ca, rMotor[1][ca]);
					fprintf(rMot, "%ld , \n", rMotor[1][ca]);
					if(ca == i){
						lcdPrint(uart1, 2, "%d , %ld", ca, rMotor[1][ca]);
						fclose(rMot);
						delay(100);
						break;
					}
				}break;
				//fwrite(rMotor, sizeof(long int), i*k, rMot);
				//fclose(Timings);
			}
				else{
					lcdPrint(uart1, 1, "aVal rM %d", a);
					lcdPrint(uart1, 2, "Init[1][1] %ld", rMotor[1][3]);
				}
				if(abs(motorGet(1) - rMotor[a][1] > c)  ||  abs(motorGet(3) - rMotor[a][2]) > c  ||
				abs(motorGet(5) - rMotor[a][3]) > c  ||  abs(motorGet(6) - rMotor[a][4]) > c  ||
				(abs(motorGet(7) - rMotor[a][5]) > c))
					{
						if(a != 20){
						rMotor[a+1][1] = motorGet(1); //StrafeWheel
						rMotor[a+1][2] = motorGet(2); //Left Side of Drive
						rMotor[a+1][3] = motorGet(3); // Right Side of Drive
						rMotor[a+1][4] = motorGet(6); // Left Arm
						rMotor[a+1][5] = motorGet(7); // Right Arm
						lcdSetBacklight(uart1, true);
						Times[a+1] = millis() - starttime;
						delay(100);
						a++;
					}
				}
				else{
					lcdSetBacklight(uart1, false);
				}
	}

}

[/CODE]
**

Arrays in C are 0 based, not 1 based.

An Array

int  a[5];

has elements
a[0], a[1], a[2], a[3], a[4]

to loop through the elements of the array

for(i=0;i<5;i++)
    a* = 0;

So in your code you eventually access array element rMotor[20][5] which is out of bounds. You also seem to flip the array indices in one of the loops.*

I did a little bit of debugging, yeah, that index flip was bad and probably created some array out of bounds error.

But after some debugging, I got an easy fix. The if(ca == [some int]) wasn’t executing as the loop would never hit 20, which makes sense. Really simple thing that overlooked.

But thank you for pointing out the index flip. I made 2 different versions of the same code on two different workstations, hence the error. I would have screwed up without you pointing it out.

of the file rMot