html - 如何更改用 c 创建和编写的 .html 文件中的一行?

标签 html c file line-breaks

我用了这个 -> 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);

最佳答案

这里有两个问题,其中之一绝对是关键:

  1. 在 HTML 中,换行符是 <br>不是\r\n
  2. 您的 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);

关于html - 如何更改用 c 创建和编写的 .html 文件中的一行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55754241/

相关文章:

css - 如何水平居中具有动态宽度的 3 个 div 元素,第一左,第二居中,第三右?

javascript - 外部 javascript 数组初始化

C 预处理器与变量的连接

php - 数据大小无限制时的有效数据存储

c - 用 C 解析文本文件

linux - 为什么我会收到 No such file or directory 异常?

php - 用我的 php 代码用 hsl 着色

Javascript从左侧动态添加div

c - 轮询()和读取() "resource temporarily unavailable"

c - 重新分配一个字符串数组