Okay, so all my code is functional. I am mostly looking for suggestions.
Right now, I have a file being read. Each line of the file has 3 different variables. These variables are being read into an array. The problem I am trying get input on it that as the file is read in the while loop, the data overwrites itself. I need all the data stored in one array with spaces between. I a not sure what it is not currently doing that. Is there a better function to be using?
Here is a sample of what I have:
char filepath[1000], filepathBP1[1000];
char BP2_ext [] = "\\BP_2.txt";
char bp2_Val1[80], bp2_Val2[80], bp2_Val3[80], bp2_Line[100];
FILE* fp;
strcpy(filepathBP1, filepath);
strcat(filepathBP1, BP1_ext);
fp = fopen(filepathBP1, "r");
if (fp == NULL)
{
puts("ERROR OPENING FILES");
exit(EXIT_FAILURE);
}
while (!feof(fp))
{
printf("\n\nREADING BP_1.txt...");
fgets(bp1_Line, 100, fp);
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);
}
fclose(fp);
abc def ghiand line 2 =pqr stu vwx, and you wantbp1_Val1to end up withabc pqrandbp1_Val2to end up withdef stuandbp1_Val3to end up withghi vwx, then you have to take steps to add the blanks and read the second line after the data added by the first line. But that information should be in the question — which you can edit.