unknown escape sequence:

How to correct this error?
args.c|35|warning: unknown escape sequence: '\-' [enabled by default]|

1
2
3
4
5
char helpStr[] = {"Usage:\n\t-h\t Displays this help message\n\t\-i\tThe name of the input image for blurring\n\
\t-g\tThe size of the gaussian kernel. Default is 3\n\
\t-s\tThe sigma parameter of the gaussian. Default is 0.8\n\
"};


gcc

BTW: Does the forum have any kind of poping ad window? I cannot close it, having avira installed, not sure is it adware or cplusplus.com ad.
Last edited on
The backslash is used for escape characters so you need to escape backslash itself if you want it in a string literal.

 
char helpStr[] = {"Usage:\\n\\t-h\\t Displays this ... 
@Peter I think they are trying to have a menu that looks something like
Usage:
    -h    Displays this help message
    -i    The name of the input for blurring
    -g    The size of the gaussin kernel. Default is 3
    -s    The signma parameter of the gaussian. Default is 0.8
\-i This is supposed to be -i

*had a typo
Last edited on
I dont think the point of the text is to display \n and \t, this should be used to generated linebreak and tab in text. But when I try to remove the backslashes on the end of lines:

1
2
3
4
char helpStr[] = {"Usage:\n\t-h\t Displays this help message\n\t\-i\tThe name of the input image for blurring\n
\t-g\tThe size of the gaussian kernel. Default is 3\n
\t-s\tThe sigma parameter of the gaussian. Default is 0.8\n
"};


so I got error missing terminating character ".

So just tell me how to separate the text on more lines if is it possible.
You also have a few other stray ones. Usage:\n\t-h\t Displays this help message\n\t\-i\tThe name of the input image for blurring\n\
\t-g\tThe size of the gaussian kernel. Default is 3\n\
\t-s\tThe sigma parameter of the gaussian. Default is 0.8\n\



Edit I see you found 3 of the 4.

By the way I don't think it wil compile to start each line put a " before and and " at the end. like
1
2
3
char helpStr[] = {"Usage:\n\t-h\t Displays this help message\n\t-i\tThe name of the input image for blurring\n"
"\t-g\tThe size of the gaussian kernel. Default is 3\n"
"\t-s\tThe sigma parameter of the gaussian. Default is 0.8\n"};
Last edited on
But it's not clear to me how to break the text in the code, for the line not to be too long.
"help message\n\t\-i\tThe name of"
note that you have written '\-' which is not a valid escape sequence
drop the backlash.


Also, to improve readability you may want to use raw string literals
1
2
3
4
5
6
7
char help[] =
R"(Usage:
	-h	Displays this help message
	-i	The name of the input image for blurring
	-g	The size of the gaussian kernel. Default is 3
	-s	The sigma parameter of the gaussian. Default is 0.8
)";
edit: scratch that, you are using C
Last edited on
nothing works
1
2
3
4
5
6
7
8
9
#include  <stdio.h>

int main()
{
    const char helpStr[] = "Usage:\n\t-h\tDisplays this help message\n\t-i\tThe name of the input image for blurring"
                           "\n\t-g\tThe size of the gaussian kernel. Default is 3\n\t-s\tThe sigma parameter of the "
                           "gaussian. Default is 0.8\n" ;
    puts(helpStr) ;
}

http://rextester.com/HDJNN12526
Thank you
Ok, now that we have realised that adjacent string literals are concatenated, let us make the code more readable (and maintainable):

1
2
3
4
5
6
7
8
9
10
11
#include  <stdio.h>

int main()
{
    const char helpStr[] = "Usage:\n"
                           "        -h    Displays this help message\n"
                           "        -i    The name of the input image for blurring\n"
                           "        -g    The size of the gaussian kernel. Default is 3\n"
                           "        -s    The sigma parameter of the gaussian. Default is 0.8\n" ;
    puts(helpStr) ;
}

http://rextester.com/XXPB22600
Topic archived. No new replies allowed.