I would like a to define a variable string in C that contains the following set of characters: a-zA-Z0-9'-_”
.
Therefore I would do it like this:
char str[64] = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789'-_""
As you can see the problem is at the end with "
character.
Question 1: How can I work around that?
Question 2: Is there a better way than my way to define a string like that?
PS: I didn't really know how to title my question, so if you got a better one, please edit it.
The basic double-quoted string is a series of characters surrounded by double quotes. If you need to use the double quote inside the string, you can use the backslash character. Notice how the backslash in the second line is used to escape the double quote characters.
To represent a double quotation mark in a string literal, use the escape sequence \". The single quotation mark (') can be represented without an escape sequence. The backslash (\) must be followed with a second backslash (\\) when it appears within a string.
' You can put a backslash character followed by a quote ( \" or \' ). This is called an escape sequence and Python will remove the backslash, and put just the quote in the string.
use the backslash: "\""
is a string containing "
like this:
char str[67] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'-_\"";
added one for the implicit '\0' at the end (and put in the missing vV) - this could also be:
char str[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'-_\"";
and let the compiler count for you - then you can get the count with sizeof(str)
;
How does it add up to 67?
a-z 26
A-Z 26
0-9 10
'-_" 4
'\0' 1
---
67
Use "\""
(backslash") for putting "
in a string
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With