lundi 30 mars 2015

Error in my switch case



So I'm trying to make an input function That takes in things separated by a comma and puts each thing into it's own array. I think I almost have it figured with this switch, but it gets stuck in the second statement. I don't know why.



/*************************************************************************

3/25/2015
This program takes in a file of the format
PART,2.000,-1,0.050,V
PART,0.975,-1,0.025,V
PART,3.000,+1,0.010,F
GAP,0.000,0.080
does the tolerance analysis
**************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define BUFFER_SIZE 1024
#define ARRAYSIZE 100
void input(char *gapPart, float *nom,float *tollerance,int *SIGNS,char *V_F,float Spec_Minnimum,float Spec_Maximum);
void toleracningPt1(int size, char gapPart[], float nom[],float tollerance[],int SIGNS[],char V_F[],float Spec_Minnimum,float Spec_Maximum);
int main(){
/**Decs**/
float nom[ARRAYSIZE]; //holds the nominal values (2.00, .975 ect)
float tollerance[ARRAYSIZE]; //holds the third value (.05, .025, ect)
int SIGNS[ARRAYSIZE]; // signifies if the value goes up or down
char gapPart[ARRAYSIZE];// holds the value if it's a gap or part
char V_F[ARRAYSIZE]; // F things cannot be changed, V things can be
int size=0;
float Spec_Minnimum=0, Spec_Maximum=0;
/**custom functions**/
input(gapPart, nom, tollerance, SIGNS, V_F, Spec_Minnimum, Spec_Maximum);
toleracningPt1(size, gapPart,nom, tollerance, SIGNS, V_F, Spec_Minnimum, Spec_Maximum);
return 0;
}
/***********************************************************************************************************/
void input(char *gapPart,float *nom,float *tollerance,int *SIGNS,char *V_F,float Spec_Minnimum,float Spec_Maximum){

const char *delimiterCharacters = " ";
const char *delimiterCharacters2 = ",";
const char *filename = "tin.txt";
FILE *inputFile = fopen( filename, "r" );
char buffer[ BUFFER_SIZE ];
char *lastToken;
int i=1, step;

printf("File Data\n");
/* usual error check*/
if(inputFile == NULL ){
fprintf( stderr, "Unable to open file %s\n", filename );
}else{
/**Prints out contents of the file **/
while( fgets(buffer, BUFFER_SIZE,inputFile) != NULL ){// while there is stuff to do this with
lastToken = strtok( buffer, delimiterCharacters );
while( lastToken != NULL ){//same song..
printf( "%s\n", lastToken );
lastToken = strtok( NULL, delimiterCharacters );// clear out lastToken
}

}

rewind(inputFile);

while( fgets(buffer, BUFFER_SIZE,inputFile) != NULL ){// while there is stuff to do this with
lastToken = strtok( buffer, delimiterCharacters2 );
while( lastToken != NULL ){//same song..
//strtok into seperate arrays
while(i=1,i<5,++i){
switch(i){
case 1:
fscanf(inputFile,"%s\n", &gapPart[i]);
printf("debug1");
++i;
break;
case 2:
printf("debug2");
fscanf(inputFile,"%f\n", &nom[i]);
++i;
break;
case 3:
printf("debug3");
fscanf(inputFile,"%d\n", &SIGNS[i]);
++i;
break;
case 4:
printf("debug4");
fscanf(inputFile,"%f\n", &tollerance[i]);
break;
case 5:
printf("debug5");
fscanf(inputFile,"%c\n", &V_F[i]);
break;
default:
printf("Error");
}
}


}
lastToken = strtok( NULL, delimiterCharacters2 );// clear out lastToken
}
}



fclose(inputFile );

}


/*****************************************************************************************************************/
void toleracningPt1(int size, char gapPart[], float nom[],float tollerance[],int SIGNS[],char V_F[],float Spec_Minnimum,float Spec_Maximum)
{
int x;
float Act_Gap, Act_Tollerance, Maximum_Gap = 0.0, Minnimum_Gap = 0.0;
for ( x=0, Act_Gap = 0; x<size; x++){ //does tolerance math
Act_Gap = Act_Gap + (nom[x]*SIGNS[x]);
}
for ( x=0, Act_Tollerance = 0; x<size; x++){
Act_Tollerance = Act_Tollerance + (tollerance[x]);
}
for (x= 0, Maximum_Gap = 0; x<size; x++){
Maximum_Gap = (nom[x]*SIGNS[x]+tollerance[x])+Maximum_Gap;
Minnimum_Gap = (nom[x]*SIGNS[x]-tollerance[x])+Minnimum_Gap;
}

printf("Actual Gap Mean: %.3f\"\n", Act_Gap); //printing
printf("Actual Gap Tolerance: %.3f\"\n", Act_Tollerance);
if (Maximum_Gap > Spec_Maximum){
printf("The maximum gap (%.3f\") is (Greater) than specified (%.3f\")\n", Maximum_Gap, Spec_Maximum);
}
if (Maximum_Gap < Spec_Maximum){
printf("The maximum gap (%.3f\") is (Less) than specified (%.3f\")\n", Maximum_Gap, Spec_Maximum);
}
if (Minnimum_Gap > Spec_Minnimum){
printf("The minimum gap (%.3f\") is (Greater) than specified (%.3f\")\n", Minnimum_Gap, Spec_Minnimum);
}
if (Minnimum_Gap < Spec_Minnimum){
printf("The minimum gap (%.3f\") is (Less) than specified (%.3f\")\n", Minnimum_Gap, Spec_Minnimum);
}
}



Aucun commentaire:

Enregistrer un commentaire