Sorry, didn't mean to leave out that section - there are a lot of parameters so I thought it'd be simpler to just show three, but ended up snipping a bit out that I didn't mean to.
Attempt #2 at posting my code - hopefully has everything needed:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
main ()
{
FILE *parameters;
char filename[100];
int ch=0;
int lineno=0;
char line[128]={'\0'};
char arra[128][3000]={{'\0'}};
char *mass, *WINGSPAN, *s;
mass=WINGSPAN=s=NULL;
float m,wingspan,S;
char *param[40];
char *param2[40];
/* Open parameters file */
printf("Type in the name of the file containing aircraft data, e.g. param.txt\n");
scanf("%100s",filename);
parameters=fopen(filename,"r");
if (parameters == NULL)
{printf("Could not open aircraft parameters file.\n"); }
else
{
while ((ch = fgetc(parameters)) != EOF)
{if (ch == '\n')
++lineno;
}
fseek(parameters, 0, SEEK_SET);
i=0;
while(fgets(line,sizeof line,parameters) !=NULL)
{strcpy (arra[i],line);
i++;
}
/* tokenise by equals sign to find parameters */
char delims[]="=";
for (i=0;i<=lineno; i++)
{
param[i]=strtok(arra[i],delims);
param2[i]=strtok(NULL,delims);
printf("param[i] is %s\n",param[i]);
printf("param2[i] is %s\n",param2[i]);
/* these prints are coming out correct */
if (strcmp("Mass*",param[i])==0) mass=param2[i];
if (strcmp("Wingspan*",param[i])==0) WINGSPAN=param2[i];
if (strcmp("Wing area*",param[i])==0) s=param2[i];
/* this is what appears to not be working */
}
/* converts tokens to float values */
//mass=param2[4]; this is what I don't want to use as it's too inflexible with line numbers
m=atof(mass);
//WINGSPAN=param2[6];
wingspan=atof(WINGSPAN);
//s=param2[8];
S=atof(s);
WL=param2[10];
wl=atof(WL);
// ditto again
printf("Mass is %f\n",m);
printf("Wingspan is %f\n",wingspan);
printf("Wing area is %f\n",S);
}
return(0);
}