Files & strings
-
I am working on a project where Im reading values from a machine every second, I then increment these values in a file, and then graph this file, every second I reset the plot and graph it again with the new values, when I reach the end of the upper bound of the x-axis, I want the lower and upper bounds to increment by 1 every second, Im working inside a forever loop and the code looks like so:
x=0; y=0; char* s; for( ;; ) //Get value and write to file. g1.plot_dataFile("data.dat", "test"); Sleep(1000); g1.reset_plot(); x++; if(x>20) //20 is the upper bound of the x-axis { y++; sprintf(s, "set xrange [%i:20+%i]", y, y); g1.cmd(s); } }
g1.cmd(string s)
is a function to send commands to an external plotting application, and needs to take strings While running, when x reaches 20, I get "Run-Time Check Failure #3 The variable 's' is being used without being defined." Any help please!!! We have a mathematician, a different kind of mathematician, and a statistician! -
I am working on a project where Im reading values from a machine every second, I then increment these values in a file, and then graph this file, every second I reset the plot and graph it again with the new values, when I reach the end of the upper bound of the x-axis, I want the lower and upper bounds to increment by 1 every second, Im working inside a forever loop and the code looks like so:
x=0; y=0; char* s; for( ;; ) //Get value and write to file. g1.plot_dataFile("data.dat", "test"); Sleep(1000); g1.reset_plot(); x++; if(x>20) //20 is the upper bound of the x-axis { y++; sprintf(s, "set xrange [%i:20+%i]", y, y); g1.cmd(s); } }
g1.cmd(string s)
is a function to send commands to an external plotting application, and needs to take strings While running, when x reaches 20, I get "Run-Time Check Failure #3 The variable 's' is being used without being defined." Any help please!!! We have a mathematician, a different kind of mathematician, and a statistician! -
I am working on a project where Im reading values from a machine every second, I then increment these values in a file, and then graph this file, every second I reset the plot and graph it again with the new values, when I reach the end of the upper bound of the x-axis, I want the lower and upper bounds to increment by 1 every second, Im working inside a forever loop and the code looks like so:
x=0; y=0; char* s; for( ;; ) //Get value and write to file. g1.plot_dataFile("data.dat", "test"); Sleep(1000); g1.reset_plot(); x++; if(x>20) //20 is the upper bound of the x-axis { y++; sprintf(s, "set xrange [%i:20+%i]", y, y); g1.cmd(s); } }
g1.cmd(string s)
is a function to send commands to an external plotting application, and needs to take strings While running, when x reaches 20, I get "Run-Time Check Failure #3 The variable 's' is being used without being defined." Any help please!!! We have a mathematician, a different kind of mathematician, and a statistician!:confused: did you post all of your code? It looks like s never gets a value at all! You simply declare it:
char *s;
But never assign anything to it. (p.s., at the very least, you should assign NULL to it when it is first created. Just good programming practice. :) ) Sometimes I feel like I'm a USB printer in a parallel universe. -
allocate a space in the s pointer before 'sprintf'ing in it try calloc or a big buffer like char s[1024] = {0}; Papa while (TRUE) Papa.WillLove ( Bebe ) ;
Excellent, that worked a charm, Thanks! We have a mathematician, a different kind of mathematician, and a statistician!
-
:confused: did you post all of your code? It looks like s never gets a value at all! You simply declare it:
char *s;
But never assign anything to it. (p.s., at the very least, you should assign NULL to it when it is first created. Just good programming practice. :) ) Sometimes I feel like I'm a USB printer in a parallel universe.Your right, I just set a large buffer for s and it worked
char s[1024] = {0};
Thanks v.m. We have a mathematician, a different kind of mathematician, and a statistician! -
I am working on a project where Im reading values from a machine every second, I then increment these values in a file, and then graph this file, every second I reset the plot and graph it again with the new values, when I reach the end of the upper bound of the x-axis, I want the lower and upper bounds to increment by 1 every second, Im working inside a forever loop and the code looks like so:
x=0; y=0; char* s; for( ;; ) //Get value and write to file. g1.plot_dataFile("data.dat", "test"); Sleep(1000); g1.reset_plot(); x++; if(x>20) //20 is the upper bound of the x-axis { y++; sprintf(s, "set xrange [%i:20+%i]", y, y); g1.cmd(s); } }
g1.cmd(string s)
is a function to send commands to an external plotting application, and needs to take strings While running, when x reaches 20, I get "Run-Time Check Failure #3 The variable 's' is being used without being defined." Any help please!!! We have a mathematician, a different kind of mathematician, and a statistician!Just curious, but shouldn't
x
be reset to 0 once it exceeds 20?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
-
Just curious, but shouldn't
x
be reset to 0 once it exceeds 20?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
No!, what i want is the graph to increment indefinatly every second, so when x reaches 20 then the lower and upper bound of the x-axis on the graph will increment, in other words the x-axis will show from 1-21, then 2-22, 3-23, and so on. We have a mathematician, a different kind of mathematician, and a statistician!