CSV to HTML translation: Difference between revisions

Content added Content deleted
(→‎{{header|C}}: Argh, bad/missing terminating tags are not obvious in a section preview.)
m (→‎{{header|C}}: some linebreaks)
Line 232: Line 232:


=={{header|C}}==
=={{header|C}}==

{{lines too long|C}}


<lang c>#include <stdio.h>
<lang c>#include <stdio.h>
Line 249: Line 247:
{
{
char *s = input;
char *s = input;
printf("<table><tr><td>");
printf("<table>\n<tr><td>");
for (s = input; *s; s++) {
for (s = input; *s; s++) {
switch(*s) {
switch(*s) {
case '\n': printf("</td></tr><tr><td>"); break;
case '\n': printf("</td></tr>\n<tr><td>"); break;
case ',': printf("</td><td>"); break;
case ',': printf("</td><td>"); break;
case '<': printf("&lt;"); break;
case '<': printf("&lt;"); break;
Line 260: Line 258:
}
}
}
}
puts("</td></tr></table>");
puts("</td></tr>\n</table>");


return 0;
return 0;
Line 270: Line 268:
$ ./csv</pre>
$ ./csv</pre>


<lang html5><table>
<lang html5><table><tr><td>Character</td><td>Speech</td></tr><tr><td>The multitude</td><td>The messiah! Show us the messiah!</td></tr><tr><td>Brians mother</td><td>&lt;angry&gt;Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!&lt;/angry&gt;</td></tr><tr><td>The multitude</td><td>Who are you?</td></tr><tr><td>Brians mother</td><td>I'm his mother; that's who!</td></tr><tr><td>The multitude</td><td>Behold his mother! Behold his mother!</td></tr></table></lang>
<tr><td>Character</td><td>Speech</td></tr>
<tr><td>The multitude</td><td>The messiah! Show us the messiah!</td></tr>
<tr><td>Brians mother</td><td>&lt;angry&gt;Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!&lt;/angry&gt;</td></tr>
<tr><td>The multitude</td><td>Who are you?</td></tr>
<tr><td>Brians mother</td><td>I'm his mother; that's who!</td></tr>
<tr><td>The multitude</td><td>Behold his mother! Behold his mother!</td></tr>
</table></lang>


=={{header|C++}}==
=={{header|C++}}==