包括双引号(")在C-字符串 [英] Include double-quote (") in C-string
问题描述
我想一个在C中定义一个变量字符串包含以下字符集: A-ZA-Z0-9'-_
I would like a to define a variable string in C that contains the following set of characters: a-zA-Z0-9'-_"
.
所以我会做这样的:
char str[64] = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789'-_""
正如你所看到的问题是在结束与字符。
问题1:如何可以解决的。
问题2:难道还有比我的方式更好的方法来定义这样的字符串
Question 2: Is there a better way than my way to define a string like that?
PS:我真的不知道该怎么标题我的问题,所以如果你有一个更好的,请编辑
PS: I didn't really know how to title my question, so if you got a better one, please edit it.
推荐答案
使用反斜杠:\\
是包含字符串
use the backslash: "\""
is a string containing "
是这样的:
char str[67] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'-_\"";
增加了一个在末尾的隐式'\\ 0'(和放置在缺少VV) - 这也可以是:
added one for the implicit '\0' at the end (and put in the missing vV) - this could also be:
char str[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'-_\"";
和让你的编译器计数 - 那么你可以用计数的sizeof(STR)
;
and let the compiler count for you - then you can get the count with sizeof(str)
;
它是如何加起来67?
a-z 26
A-Z 26
0-9 10
'-_" 4
'\0' 1
---
67
这篇关于包括双引号(")在C-字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!