Hi,
I have linked SWMM 5.0 with an optimization module and using C++.
I wanted to print some results from the simulation to an external text file.
I've used the following codes, however, I can't get the results printed. Instead of that I am just getting printed "STO[0]" inside the text file.
Could anyone help me on this issue?
float STO[100];
FILE*f4;
OpenSwmmOutFile("f3.out");
for(t=1; t<=1; t++)
{
GetSwmmResult(3, 0, 12, t, &STO[0]);
f4=fopen("f4.txt", "w");
fprintf (f4, "STO[0]");
fclose(f4);
}
CloseSwmmOutFile();
Is this the correct way to print results in an external file?
Thanks a lot.
Replies
Hi, thanks a lot for the suggestion. I tried it and still got the same word printing instead of the variable values.
Then I tried with fprintf (f4, STO); instead of fprintf (f4, "STO[0]"); which just gave me attached file.
Any reasons why I am not getting the variable values?
Hi, I am fairly certain that you need to open the file f4 at the start and close it at the end. It looks like you are opening, writing one line and then closing your file. You are writing a phrase instead of a variable.