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

Thread Starter

Jswale

Joined Jun 30, 2015
121
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
 

John P

Joined Oct 14, 2008
2,026
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.
 

Thread Starter

Jswale

Joined Jun 30, 2015
121
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.
 

John P

Joined Oct 14, 2008
2,026
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:
<html>
<head>
<title>this is the title</title>
</head>
<body>
etc etc
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.
 
Top