为什么要打印安装台的空间?
这是echo
实用程序程序。它从控制台读取命令行参数,并将其打印回控制台。在以下代码块中,在第10行中,为什么在没有参数字符串结束时将空间写入控制台?
#include "kernel/types.h"
#include "kernel/stat.h"
#include "user/user.h"
int main(int argc, char *argv[])
{
int i;
for(i = 1; i < argc; i++){
write(1, argv[i], strlen(argv[i]));
if(i + 1 < argc){
write(1, " ", 1); //line 10
} else {
write(1, "\n", 1);
}
}
exit(0);
}
This is the echo
utility program. It reads the command-line argument from the console and prints it back to the console. In the following block of code, at line 10, why write a space to the console when there is not the end of argument string?
#include "kernel/types.h"
#include "kernel/stat.h"
#include "user/user.h"
int main(int argc, char *argv[])
{
int i;
for(i = 1; i < argc; i++){
write(1, argv[i], strlen(argv[i]));
if(i + 1 < argc){
write(1, " ", 1); //line 10
} else {
write(1, "\n", 1);
}
}
exit(0);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这仅在最后一个参数之后才打印出新线,否则它将打印一个空间以分开相邻参数。换句话说,输出是单线中的参数,被空间隔开,以纽线结束线路。
This simply prints newline after the last argument only, otherwise it prints a space to separate adjacent arguments. In other words, output is arguments in the single line, separated by spaces, ending the line with newline.