Code:
/* ------------------- */
/* Include Information */
/* ------------------- */
#include <stdio.h>
#include <math.h>
#define FILENAME "Misc.txt"
#define FILENAME2 "LRSCC.txt"
#define FILENAME3 "MGC.txt"
#define FILENAME4 "MCTC.txt"*/
int NUMOFDATAPOINTS;
/*int NUMOFDATAPOINTS;*/
char filename[19];
/* #define NUMOFDATAPOINTS 10
/* nclude <koolplotX.h> */
/* -------- */
/* Int Main */
/* -------- */
int main(void)
{
/* ------------------------ */
/* Declaration of Variables */
/* ------------------------ */
printf( "Please enter the name of the file you would\nlike to read data from: " );
scanf( "%s",&filename );
if( (strcmp( filename, "MISC.txt") == 0) || (strcmp( filename, "LRSCC.txt") == 0) || (strcmp( filename, "MGC.txt") == 0) || (strcmp( filename, "MCTC.txt") == 0) )
{
if ((strcmp( filename, "MISC.txt") == 0))
{
}
if ((strcmp( filename, "LRSCC.txt") == 0))
{
}
if ((strcmp( filename, "MGC.txt") == 0))
{
;
}
if ((strcmp( filename, "MCTC.txt") == 0))
{
}
}
else
{
printf("Wrong info");
}
/* --------------------------------- */
/* Declaration of funct. prototypes. */
/* ---------------------------------
int meanofxa(int positionofclay[]);
double meanofya(double distanceofclay[]);
double calcofa(double paramatera[]);
double calcofb(double paramaterb[]);
/* ------------------------------------------------------- */
/* Opening up our file and declaring the file! (read only) */
/* ------------------------------------------------------- */
FILE *misc;
misc = fopen("MISC.txt", "r");
FILE *lrscc;
lrscc = fopen("LRSCC.txt", "r");
FILE *mgc;
mgc = fopen("MGC.txt", "r");
FILE *mctc;
mctc = fopen("MCTC.txt", "r");
int count, positionofclay[NUMOFDATAPOINTS];
double distanceofclay[NUMOFDATAPOINTS], distance, paramatera, paramaterb;
double differenceofx[NUMOFDATAPOINTS], sqrta, sqrtb, correlationa;
double correlation, powa, meanofx, meanofy, differenceofy[NUMOFDATAPOINTS];
double sumofallxsquares, sumofallysquares, squareofx[NUMOFDATAPOINTS], squareofy[NUMOFDATAPOINTS];
double diffxbydiffy[NUMOFDATAPOINTS], countofdiffxbydiffy=0, lineofbestfit[NUMOFDATAPOINTS];
char windowtitle[120];
const char * header = "sampleX: ";
/* ---------------------------------------------------------- */
/* If file isn't there or can't be open, flag user with error */
/* ---------------------------------------------------------- */
if ((misc == NULL) || (lrscc == NULL) || (mgc == NULL) || (mctc == NULL))
{
printf("Can't open file, there is a problem \n");
exit(1);
}
/* ---------------------------------------------------------- */
/* Time to put all of the data in the misc.txt file to arrays */
/* ---------------------------------------------------------- */
/*
else
{
for(count=0; count<=NUMOFDATAPOINTS-1; count++)
{
fscanf(misc, "%i%lf",&positionofclay[count], &distanceofclay[count]);
}
}
/* ------------------------------------------------------------------------------------- */
/* This section displays the array information on screen (info obtained from "misc.txt") */
/* ------------------------------------------------------------------------------------- */
if( (strcmp( filename, "MISC.txt") == 0) || (strcmp( filename, "LRSCC.txt") == 0) || (strcmp( filename, "MGC.txt") == 0) || (strcmp( filename, "MCTC.txt") == 0) )
{
if( (strcmp( filename, "MISC.txt") == 0) ) {
for(count=0; count<=NUMOFDATAPOINTS-1; count++)
{
fscanf(misc, "%i%lf",&positionofclay[count], &distanceofclay[count]);
}
printf("\nMISC.txt contains the following plot information:\n\n");
printf("--------------\n");
for(count=0; count<=NUMOFDATAPOINTS-1; count++)
{
printf("%i\t%2.4f\n",positionofclay[count], distanceofclay[count]);
fclose(misc);
}
printf("--------------\n");
}
else
if( (strcmp( filename, "LRSCC.txt") == 0) ) {
for(count=0; count<=NUMOFDATAPOINTS-1; count++)
{
fscanf(lrscc, "%i%lf",&positionofclay[count], &distanceofclay[count]);
}
printf("\nLRSCC.txt contains the following plot information:\n\n");
printf("--------------\n");
for(count=0; count<=NUMOFDATAPOINTS-1; count++)
{
printf("%i\t%2.4f\n",positionofclay[count], distanceofclay[count]);
fclose(lrscc);
}
printf("--------------\n");
}
else
if( (strcmp( filename, "MGC.txt") == 0) ) {
for(count=0; count<=NUMOFDATAPOINTS-1; count++)
{
fscanf(mgc, "%i%lf",&positionofclay[count], &distanceofclay[count]);
}
printf("\nMGC.txt contains the following plot information:\n\n");
printf("--------------\n");
for(count=0; count<=NUMOFDATAPOINTS-1; count++)
{
printf("%i\t%2.4f\n",positionofclay[count], distanceofclay[count]);
fclose(mgc);
}
printf("--------------\n");
}
else
if( (strcmp( filename, "MCTC.txt") == 0) ) {
for(count=0; count<=NUMOFDATAPOINTS-1; count++)
{
fscanf(mctc, "%i%lf",&positionofclay[count], &distanceofclay[count]);
}
printf("\nMCTC.txt contains the following plot information:\n\n");
printf("--------------\n");
for(count=0; count<=NUMOFDATAPOINTS-1; count++)
{
printf("%i\t%2.4f\n",positionofclay[count], distanceofclay[count]);
fclose(mctc);
}
printf("--------------\n");
}
}
else
{
printf("\nYou entered an incorrect filename...it should be misc.txt or MISC.txt\n");
exit(1);
}
/* -------------------------------------------------------------------------------------- */
/* According to the calculations, the following formula must be used to compute paramater */
/* "a" of the "y = a*x + b" formula: */
/* */
/* N ( X - M(ofx) ) * ( Y - M(ofy) ) */
/* --------------------------------- */
/* N ( X - M(ofx) ) ^ 2 */
/* */
/* So...let's do the mean x and y values first it! */
/* -------------------------------------------------------------------------------------- */
meanofx=0;
for(count=0; count<=NUMOFDATAPOINTS-1; count++)
{
meanofx = (double)positionofclay[count] + meanofx;
}
meanofx = meanofx / NUMOFDATAPOINTS;
meanofy=0;
for(count=0; count<=NUMOFDATAPOINTS-1; count++)
{
meanofy = (double)distanceofclay[count] + meanofy;
}
meanofy = meanofy / NUMOFDATAPOINTS;
/* ---------------------------------------------- */
/* Now we can print our obtained values on screen */
/* ---------------------------------------------- */
printf("\nAfter using the calculation method, the mean 'x' and 'y' values are:\n\n");
printf("MEAN of X: %2.2f\n",meanofx);
printf("MEAN of Y: %2.2f\n",meanofy);
As you can see "NUMOFDATAPOINTS" is used throughout the code, so I need to to be active prior to starting the calculations, that's where I'm stick.