html - 如何更改用 c 创建和编写的 .html 文件中的一行?
问题描述
我使用了这个 ->fprintf(file, "\r\n");
但没有换行。
我有一个用 c 编写的网络服务器。连接后,我创建了一个包含如下内容的 html 文件:
This file was saved at :Fri Apr 19 00:49:43 2019 (line break!)
Please click here.
代码:
file = fopen("testvideo.html", "w");
if (file == NULL)
{
/* File not created hence exit */
printf("Unable to create file.\n");
exit(EXIT_FAILURE);
}
time(&tv);
timestr = ctime(&tv);
fprintf(file, "<html> The file was saved at:</html>");
fprintf(file, timestr);
fprintf(file, "\r\n");
fprintf(file,"<html> Please click :<a href=\"http://whatevevevever.com/testvideo.mp3\"\>HERE<a></html>");
fclose(file);
解决方案
这里有两个问题,其中一个绝对是关键:
- 在 HTML 中,换行符
<br>
不是\r\n
- 您的 HTML 不正确(或有效)。我不会在这里提供 HTML 教程,但您需要为您的 HTML 使用正确的结构,以确保浏览器能够正确呈现它。
更正的代码:
if (file == NULL)
{
/* File not created hence exit */
printf("Unable to create file.\n");
exit(EXIT_FAILURE);
}
time(&tv);
timestr = ctime(&tv);
fprintf(file, "<html> <body>The file was saved at:");
fprintf(file, timestr);
fprintf(file, "<br>Please click :<a href=\"http://whatevevevever.com/testvideo.mp3\"\>HERE<a></body></html>");
fclose(file);
推荐阅读
- c - 我该怎么做,c 中的命令行参数
- python - 用特定索引替换另一个列表中的数据框值
- javascript - 带有画布的Javascript循环图像
- redux - 如何在 React 类组件中使用 Redux 与多个 React 提供程序连接?
- forms - 在 Delphi Form Designer 中实时查看表单?
- performance - 建造时间需要永远
- python - 如何在 numpy.matrix 中添加 numpy.array?
- excel - 如何使用 ListIndex 查找 Combobox 值的行?
- c# - AutoMapper ITypeConverter 问题
- html - Bootstrap:如何通过文本换行和响应使图像向右浮动?