c++ - 函数 strlen() 的返回值?
问题描述
解决方案
If you have a string with 7 characters, the array indexes of the printable characters go from 0 to 6, and strlen()
will return 7
. a[7]
contains the null terminator character.
So if you start your loop from j = len
, the first character it prints is the null character, then it will print the printable characters in the remaining iterations. If you start your loop from len-1
, it will print only the printable characters.
The extra spacing you're seeing is that null character. On some operating systems, printing a null character has no visible effect, but on your system it apparently prints a space.
推荐阅读
- python - 网页中的图像不更新
- ubuntu - ReferenceError:未定义 gulp
- php - 将路径从 url 指向 .htaccess 中的目录
- postman - 我应该使用哪个凭证来生成令牌,然后使用 Postman 在 Keycloak DB 中创建用户?
- ios - Flutter 将不再使用 Firebase 在 iOS 上构建
- python - 从 YouTube-DL 下载的音频文件已损坏
- reactjs - 如何从材质ui中的`Select`获取`MenuItem`中的自定义数据属性值?
- python - Python - 使用类型提示时出现 NameError
- javascript - 当父状态被子状态更改时,useEffect 没有第一次被调用
- java - 如何在原型作用域bean上应用spring aop方面