avertissement: inconnu séquence d'échappement: '\040' [activé par défaut]
Je suis en train d'écrire une application simple en C, ce qui, je tiens à publier sous licence BSD. Une partie de l'application est responsable de l'impression des informations sur le programme de ses utilisateurs. Cependant, j'ai un problème avec l'impression du texte de la licence. Voici l'exemple:
#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;
}
- Je compiler mon application en utilisant gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.11
sur Kubuntu 13.10. J'ai eu ce message d'avertissement:
warning: unknown escape sequence: '0' [enabled by default]
const char *license = "\n\
^
Comment puis-je me débarrasser de lui? J'ai promis à moi-même d'écrire un code sans erreurs et avertissements. C'est une simple application C.
EDIT:
Merci à vous tous, voici le bon de travail, les mises en garde-gratuit code:
#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;
}
- Avez-vous googlé "séquence d'échappement 040"?
- Oui, je l'ai fait, mais l'ajout d'un autre caractère `\` simplement des résultats dans le pas-de traiter le texte de la licence de l'ensemble du texte à imprimer
- Avez-vous des "\[espace]" à la fin d'une ou plusieurs lignes? Essayez cette réponse bytes.com/topic/c/answers/... Si oui, remplacer "\ " par "\" qui indique au compilateur pour continuer le sens littéral du texte sur la ligne suivante.
- Je n'ai pas d'espace à la fin, juste "
\\[Enter]
", donc il ne m'a pas fait (essayé)
Vous devez vous connecter pour publier un commentaire.
Dans votre code, vous avez cette ligne (la dernière ligne du texte de l'accord), qui est ce qui est à l'origine de l'erreur:
"\n\ \n";
Barre oblique inverse-l'espace n'est pas une séquence d'échappement. Le message "040" est un espace de char en octal, signifié par le 0.
Il semble que, quelque part dans la définition de la licence il y a un vide à la suite de \ et avant le caractère de nouvelle ligne.
Par exemple
ou peut-être dans quelques autres de la ligne de la multiligne définition.
Il serait plus simple d'écrire la définition de la manière suivante
Cet avertissement, fondamentalement, se pose lorsque vous avez une barre oblique inverse [] suivi d'un espace et donc, lorsque nous l'exécuter en le considérant seulement comme un avertissement, il manque "TOUTES LES barres obliques INVERSES QUI SONT SUIVIES PAR des ESPACES". en faisant ainsi un manque motif ...
Pour corriger cela, il suffit de rajouter une autre barre OBLIQUE inverse à côté des barres obliques inverses qui relèvent de cette catégorie, ainsi, ce qui contribue à l'impression de la prochaine barre oblique inverse à celui qui était devant l'espace.
Pour comprendre cela, considérons cet exemple..
programme:
compiliation: dit "inconnu séquence d'échappement"
de sortie: +
------------------------------------------------------------------------------
cosider, du même code, dans l'instruction printf utiliser une autre barre oblique inverse entre
[\ & +]
je.e
maintenant la sortie serait
de sortie: +
Merci <3