Sorry, to include the code again.
I'm trying to figure out how the arrays will work here but am having a problem
because when I define the variable forcevertex[]
I need it to be a char string containing the following information:
Code:
forcevertex[j]=("Vertex %i: Forced: (%.3f, %.3f, %.3f) Real: (%.3f, %.3f, %.3f) \n",j,Xforce,Yforce,Zforce,Xreal,Yreal,Zreal);
But if I define the variable char forcevertex[8], trying to account for the 8 vertices that will be created, the program will interpret the 8 as the string length rather than the array.
So, I'm confused.
Help please?
Thanks so much.
Code:
#include <iostream>
int main (void) {
/* Variables */
float Xreal;
float Yreal;
float Zreal;
float Xforce;
float Yforce;
float Zforce;
float Tval;
char inZforce[64];
int check_input;
char input_buffer[160];
int wloop = 8;
int j; /* vertex number */
char forcevertex[8];
/* Prompts */
/* Loop */
for(wloop = 7; wloop >= 0; wloop--)
{
/* Set vertex-number for loop pass */
j=8-wloop;
/* Get coordinates of real point */
printf("Real-Point values in (x, y, z) ");
fgets(input_buffer, sizeof input_buffer, stdin);
check_input = sscanf(input_buffer, "(%f,%f,%f)", &Xreal, &Yreal, &Zreal);
while (check_input !=3) {
//Improper format
printf("Improper format.");
return(0);
};
/* Get Z coordinate of forced point */
printf("Zforce value: ");
fgets(inZforce, sizeof inZforce, stdin);
Zforce=strtof(inZforce, NULL);
/* Computation */
Tval=Zforce/Zreal;
Xforce=Tval*Xreal;
Yforce=Tval*Yreal;
/* Output Display */
printf(" \n");
printf("Forced Point: (%.3f, %.3f, %.3f) \n",Xforce,Yforce,Zforce);
printf("Real Point: (%.3f, %.3f, %.3f) \n",Xreal,Yreal,Zreal);
printf("T-value: %.3f \n",Tval);
printf(" \n");
/* Save vertex information before going to next one */
forcevertex[j]=("Vertex %i: Forced: (%.3f, %.3f, %.3f) Real: (%.3f, %.3f, %.3f) \n",j,Xforce,Yforce,Zforce,Xreal,Yreal,Zreal);
} /* End Loop */
/* Final Display */
printf("Vertex creation complete. \n");
/* Then display Force-Vertex 0-7 coords */
printf("%s \n",forcevertex[0]);
printf("%s \n",forcevertex[1]);
printf("%s \n",forcevertex[2]);
printf("%s \n",forcevertex[3]);
printf("%s \n",forcevertex[4]);
printf("%s \n",forcevertex[5]);
printf("%s \n",forcevertex[6]);
printf("%s \n",forcevertex[7]);
return(0);
}