Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to print out ascii characters from 0 to 255 in C, displayed in a webpage through Django?
    text
    copied!<p>I'm working on a C assignment for school. Here's the exact wording of the assignment:</p> <p>"Write a program that prints a list of the integers 0 through 255 and the corresponding ASCII character. "</p> <p>The actual code was simple enough:</p> <pre><code>#include &lt;stdio.h&gt; int main() { int i; for (i = 0; i &lt;= 256; i++) { printf("%d --&gt; %c\n", i, i); } return 0; } </code></pre> <p>However, I need to display this output in a webpage with Django. I compiled this code with gcc (with the -std=C99 option enabled), and it outputs fine. However, within the webpage, this does not output anything. Our Django view is using popen2 to open the executable with this code:</p> <pre><code>if os.path.isfile(file_sh): output = popen2.popen2(file_sh)[0].read() </code></pre> <p>and the page has been tested to function with all other C code for this class. I've added a print statement within the view to verify that the output of the code is being sent to the browser correctly, and it gets displayed correctly in the terminal but not the browser. In fact, it's not being displayed at all in the browser. Upon further inspection, there is absolutely nothing within the tag this page would normally display the output of the code. I'm guessing this has something to do with character encoding. Any ideas?</p> <p>EDIT: I forgot to mention that in my template, I specified the character encoding to be utf-8 with the meta tag.</p> <p>EDIT 2: A friend of mine has a version that displays the contents of a text file saved on Windows as utf-8 at <a href="http://geekingreen.dyndns.org/week02/Assignment-5" rel="nofollow">http://geekingreen.dyndns.org/week02/Assignment-5</a>, but if he tries to display that page with output from an executable, he gets the same problem as me.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload