Okay, so this is a part of a larger project and it has turned into an over whelming mess. I have attached a few examples from the program.
What I am trying to do, is open a certain number of files to be read based off of the users input for a previous question. The user needs to also give the path to the folder, and I have to append the string with the filenames, which I haven't done yet because I am unsure of how I want to do that. But that isn't the issue at the moment. My problem is is that all my file pointers are errors, and my compiler is also saying that I have mismatched values that I am trying to compare, which I am not really sure why I am having that problem. Do you guys see anything/ know why my code is not working?
I have also attached a screen shot from one of the compilers I have tried. (yes I tried different ones, because there have been times that I have had massive errors, and then I changed compilers and they went away)
int bpSensors;
int hrSensors;
int btSensors;
//values read passed to other functions
char bp1_Val1[20], bp1_Val2[20], bp1_Val3[20], bp1_Line[100],
bp2_Val1[20], bp2_Val2[20], bp2_Val3[20], bp2_Line[100],
bp3_Val1[20], bp3_Val2[20], bp3_Val3[20], bp3_Line[100],
bp4_Val1[20], bp4_Val2[20], bp4_Val3[20], bp4_Line[100],
bp5_Val1[20], bp5_Val2[20], bp5_Val3[20], bp5_Line[100];
char filepath[1000];
//file pointers
FILE* fpBP1, fpBP2, fpBP3, fpBP4, fpBP5;
printf("Enter the path to the file holding the data files:");
fflush(stdin);
scanf("%s", filepath);
if (bpSensors == 1)
{
fpBP1 = fopen(filepath, "r");
if (fpBP1 == NULL)
{
puts("ERROR OPENING FILES");
exit(EXIT_FAILURE);
}
else
{
while (!feof(fpBP1))
{
printf("\n\nREADING BP_1.txt...");
fgets(bp1_Line, 100, fpBP1);
sscanf(bp1_Line, "%s\t%s\t%s", bp1_Val1, bp1_Val2, bp1_Val3);
printf("%s\t%s\t%s\n", bp1_Val1, bp1_Val2, bp1_Val3);
}
}
}// end BP Sensor = 1
/////////////BP Sensors = 2//////////////////
{
if (bpSensors == 2)
{
//open file 1 &2
fpBP1 = fopen(filepath, "r");
fpBP2 = fopen(filepath, "r");
//if they dont open, error shoots
if (fpBP1 == NULL)
{
puts("ERROR OPENING FILES");
exit(EXIT_FAILURE);
}
fpBP2 = fopen(filepath, "r");
if (fpBP2 == NULL)
{
puts("ERROR OPENING FILES");
exit(EXIT_FAILURE);
}
else
{
while (!feof(fpBP1))
{
printf("\n\nREADING BP_1.txt...");
fgets(bp1_Line, 100, fpBP1);
sscanf(bp1_Line, "%s\t%s\t%s", bp1_Val1, bp1_Val2, bp1_Val3);
printf("%s\t%s\t%s\n", bp1_Val1, bp_Val2, bp_Val3);
}
while (!feof(fpBP2))
{
printf("\n\nREADING BP_2.txt...");
fgets(bp2_Line, 100, fpBP2);
sscanf(bp2_Line, "%s\t%s\t%s", bp2_Val1, bp2_Val2, bp2_Val3);
printf("%s\t%s\t%s\n", bp2_Val1, bp2_Val2, bp2_Val3);
}
}
}
}// end BP = 2
//////////////////BP Sensors = 3//////////////
{
if (bpSensors == 3)
{
//open file 1 -3
fpBP1 = fopen(filepath, "r");
fpBP2 = fopen(filepath, "r");
fpBP3 = fopen(filepath, "r");
//if they dont open, error shoots
fpBP1 = fopen(filepath, "r");
if (fpBP1 == NULL)
{
puts("ERROR OPENING FILES");
exit(EXIT_FAILURE);
}
fpBP3 = fopen(filepath, "r");
if (fpBP3 == NULL)
{
puts("ERROR OPENING FILES");
exit(EXIT_FAILURE);
}
fpBP2 = fopen(filepath, "r");
if (fpBP2 == NULL)
{
puts("ERROR OPENING FILES");
exit(EXIT_FAILURE);
}
//read both files
//if there open. files 1 -3 are read and displayed
else
{
while (!feof(fpBP1))
{
printf("\n\nREADING BP_1.txt...");
fgets(bp1_Line, 100, fpBP1);
sscanf(bp1_Line, "%s\t%s\t%s", bp1_Val1, bp1_Val2, bp1_Val3);
printf("%s\t%s\t%s\n", bp1_Val1, bp_Val2, bp_Val3);
}
while (!feof(fpBP2))
{
printf("\n\nREADING BP_2.txt...");
fgets(bp2_Line, 100, fpBP2);
sscanf(bp2_Line, "%s\t%s\t%s", bp2_Val1, bp2_Val2, bp2_Val3);
printf("%s\t%s\t%s\n", bp2_Val1, bp2_Val2, bp2_Val3);
}
while (!feof(fpBP3))
{
printf("\n\nREADING BP_3.txt...");
fgets(bp3_Line, 100, fpBP3);
sscanf(bp3_Line, "%s\t%s\t%s", bp3_Val1, bp3_Val2, bp3_Val3);
printf("%s\t%s\t%s\n", bp3_Val1, bp3_Val2, bp3_Val3);
}
}
}
}// end BP = 3
This code follows this pattern for about 800 lines.