gpt4 book ai didi

c - 警告 : unknown escape sequence: '\040' [enabled by default]

转载 作者:太空狗 更新时间:2023-10-29 16:06:45 27 4
gpt4 key购买 nike

我正在用 C 编写一个简单的应用程序,我想在 BSD 许可下发布它。应用程序的一部分负责向其用户打印有关程序的信息。但是,我在打印许可文本时遇到问题。这是示例:

#include <stdio.h>
#include <stdlib.h>

void show_license(void)
{
const char *license = "\n\
Copyright (c) 2012 \n\
All rights reserved.\n\
\"Redistribution and use in source and binary forms, with or without\n\
modification, are permitted provided that the following conditions are\n\
met:\n\
\n\
* Redistributions of source code must retain the above copyright\n\
notice, this list of conditions and the following disclaimer.\n\
* Redistributions in binary form must reproduce the above copyright\n\
notice, this list of conditions and the following disclaimer in\n\
the documentation and/or other materials provided with the\n\
distribution.\n\
* Neither the name of XXX and its Subsidiary(-ies) nor the names\n\
of its contributors may be used to endorse or promote products derived\n\
from this software without specific prior written permission.\n\
\n\
\n\
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n\
\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n\
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n\
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n\
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n\
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n\
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n\
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n\
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n\
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n\
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\"\n\
\n\
\n\ \n";

fputs("\n", stderr);
fputs(license, stderr);
fputs("\n", stderr);
}


int main()
{
show_license();
return 0;
}

我在 Kubuntu 13.10 上使用 gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.11 编译我的应用程序。我收到此警告消息:

warning: unknown escape sequence: '\040' [enabled by default]
const char *license = "\n\
^

我怎样才能摆脱它?我向自己保证要编写没有任何警告和错误的代码。这是一个普通的 C 应用程序。

编辑:

谢谢大家,这是正常工作、无警告的代码:

#include <stdio.h>
#include <stdlib.h>

void show_license(void)
{
const char *license = "\n \
Copyright (c) 2012 \n\
All rights reserved.\n\
\"Redistribution and use in source and binary forms, with or without\n\
modification, are permitted provided that the following conditions are\n\
met:\n\
\n\
* Redistributions of source code must retain the above copyright\n\
notice, this list of conditions and the following disclaimer.\n\
* Redistributions in binary form must reproduce the above copyright\n\
notice, this list of conditions and the following disclaimer in\n\
the documentation and/or other materials provided with the\n\
distribution.\n\
* Neither the name of XXX and its Subsidiary(-ies) nor the names\n\
of its contributors may be used to endorse or promote products derived\n\
from this software without specific prior written permission.\n\
\n\n\
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n\
\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n\
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n\
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n\
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n\
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n\
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n\
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n\
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n\
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n\
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\"\n\
\n\n\n";

fputs("\n", stderr);
fputs(license, stderr);
fputs("\n", stderr);
}


int main()
{
show_license();
return 0;
}

最佳答案

在您的代码中,您有这一行(协议(protocol)文本的最后一行),这是导致错误的原因:

"\n\\n";

反斜杠空格不是有效的转义序列。消息“040”是八进制的空格字符,由前导 0 表示。

关于c - 警告 : unknown escape sequence: '\040' [enabled by default],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27679851/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com