Displaying data from a C++ program in a html file

Discussion in 'Programmer's Corner' started by Jswale, May 31, 2016.

  1. Jswale

    Thread Starter Member

    Jun 30, 2015
    121
    6
    Hi All,

    I am competent in C++ but I am trying to do something new.

    I want to get some User data from a cmd line from UART and store it as a variable in a C program, which I have done. Now I want to display that variable (e.g. 250) in a html document.

    I have set up a web server and have connected to it and can connect to the ip address but I am looking for Code advice for how I can display the variable.

    Regards
    Jack
     
  2. John P

    AAC Fanatic!

    Oct 14, 2008
    1,632
    224
    You could write a new HTML file every time the variable changes. Or you could use PHP (about which I know zero) which I believe could do something like read a text file, previously written by the C program, and handle it in the HTML program.
     
  3. Jswale

    Thread Starter Member

    Jun 30, 2015
    121
    6
    Thanks for the reply.

    Would the HTML file be written within the C program?

    The PHP solution I am familiar with but adds extra overheads.
     
  4. John P

    AAC Fanatic!

    Oct 14, 2008
    1,632
    224
    I'm not clear to me what you mean by "written within the C program". You could have successive fprintf() lines in your C code which would generate the HTML, as in
    Code (Text):
    1.  
    2. <html>
    3. <head>
    4. <title>this is the title</title>
    5. </head>
    6. <body>
    7. etc etc
    8.  
    so in that sense, it would be "in the C program". But you could also generate the HTML by reading successive lines from a text file and writing them out again, and just adding the data that you want to convey, when you get to the right point in the file. That way the HTML code would be basically external to the C program, but would be available when needed.

    Both of these schemes might lead to problems with reading the HTML at the exact moment when the C program updates it (i.e. overwrites an existing file with a new one). I don't know what to expect if that happens.
     
Loading...