开发者

visual basic to c string literals "\\.\" and "\"

In visual basic I have the following 2 开发者_运维知识库strings:

"\\.\" & "\"

How do I represent them in C?

Also, & in VB is the concatenation operator?


Like this:

"\\\\.\\"
"\\"


The \ is an escape character so if you want to print \ you need to put two of them: \\

To concatenate two string you can use strcat(string1, string 2) which is shown here.


As others have said, the backslash character () in C is an escape character. Look at http://msdn.microsoft.com/en-us/library/h21280bw%28VS.80%29.aspx to find more about it.

So your strings come out as follows:

"\\.\" is "\\\\.\\"
"\" is "\\"

There are many ways to concatenate strings.

puts("Hello" " " "World");

will print "Hello World".

A common way is to use strcat().

char szBuff[60];                  /* szBuff is an array of size 60 */
strcpy(szBuff, "Hello");          /* szBuff contains "Hello" */
strcat(szBuff, " World");         /* szBuff contains "Hello World" */
strcat(szBuff, " from Michael");  /* now contains  the whole sentence */
strcpy(szBuff, "New message");    /* strcpy overwrites the old contents */
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜