Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Files & strings

Files & strings

Scheduled Pinned Locked Moved C / C++ / MFC
data-structureshelp
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    roadragedave
    wrote on last edited by
    #1

    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!

    N J D 3 Replies Last reply
    0
    • R roadragedave

      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!

      J Offline
      J Offline
      jmkhael
      wrote on last edited by
      #2

      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 ) ;

      R 1 Reply Last reply
      0
      • R roadragedave

        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!

        N Offline
        N Offline
        Navin
        wrote on last edited by
        #3

        :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.

        R 1 Reply Last reply
        0
        • J jmkhael

          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 ) ;

          R Offline
          R Offline
          roadragedave
          wrote on last edited by
          #4

          Excellent, that worked a charm, Thanks! We have a mathematician, a different kind of mathematician, and a statistician!

          1 Reply Last reply
          0
          • N Navin

            :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.

            R Offline
            R Offline
            roadragedave
            wrote on last edited by
            #5

            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!

            1 Reply Last reply
            0
            • R roadragedave

              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!

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              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)

              R 1 Reply Last reply
              0
              • D David Crow

                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)

                R Offline
                R Offline
                roadragedave
                wrote on last edited by
                #7

                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!

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups