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

问题描述 投票:-3回答:1

我使用了这个 - > 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 c file line-breaks
1个回答
0
投票

你有两个问题,其中一个绝对是关键:

  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);
© www.soinside.com 2019 - 2024. All rights reserved.