I'm going to write a code that separates the string I received from the txt file into if statements.
Yes)
This is how you create a variable and store the input string.
char VecFun[10];
fpInput = fopen("input.txt", "r");
fgets(VecFun, sizeof(VecFun), fpInput);
fclose(fpInput);
And I want to distinguish between Add and Dot.
if (VecFun == "Add") {
Vector vectorO = vectorA.Add(vectorB);
fpOutput = fopen("output.txt", "w");
fprintf(fpOutput, "%.f %.f %.f", vectorO.x, vectorO.y, vectorO.z);
fclose(fpOutput);
}
else if (VecFun == "Dot") {
fpOutput = fopen("output.txt", "w");
fprintf(fpOutput, "%.f", vectorA.DotProduct(vectorB));
fclose(fpOutput);
}
else {
printf("Invalid format". (%s)\n", VecFun);
}
But the if statement doesn't work as I thought. Debugging with printf("%s", VecFun);
Here's the result. How do you get an if statement to work successfully?
c++ file-io
Compare using strcmp function.
© 2024 OneMinuteCode. All rights reserved.