How to pass in a null character in a command line argument in C?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 23:46:36

You cannot.

The C program receives arguments as zero-terminated strings. Such a string cannot contain a null character, by definition.

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 strings are null-terminated, so passing strings containing NUL characters is not possible in C. :-P

Now, if you just wanted a way to convert \0 (in the user input, i.e., "\\0" as a C string) into actual NUL characters, that's another matter. In that case, your program just needs a parser to treat \0 as separators.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!