如何在用C命令行参数空字符传递? [英] How to pass in a null character in a command line argument in C?
问题描述
我还是想知道如何在一个空字符传递作为命令行参数,也许让一个字符串可以传递作为形式参数:
I would still like to know how to pass in a null character as a command line argument, maybe so that a single string can be passed in as an argument in the form:
到\\ 0BE \\ 0or \\ 0not \\ 0℃至\\ 0BE \\ 0
"to\0be\0or\0not\0to\0be\0"
,然后解析它。
然而该计划将处理这个字符串:
And then parse it. However the program would treat this string as:
到\\\\ \\\\ 0BE \\\\ 0or \\\\ 0not \\\\ 0℃至\\\\ 0BE 0
"to\\0be\\0or\\0not\\0to\\0be\\0"
我如何解决此问题?有什么办法?
How can I work around this? Is there any way?
推荐答案
您不能。
C程序接收参数作为零结尾的字符串。这样的字符串不能包含空字符,顾名思义。
The C program receives arguments as zero-terminated strings. Such a string cannot contain a null character, by definition.
如果你想传递一个空字符,则必须有所EN code将其与一些语法和C程序必须然后去code将其通过跨preting这种语法。
If you want to pass a null character, then you must somewhat encode it with some syntax, and your C program must then decode it by interpreting that syntax.
这篇关于如何在用C命令行参数空字符传递?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!