C 打印到标准输出时去掉问号
我想去掉问号。STDIN和STDOUT。但我似乎失败了C 打印到标准输出时去掉问号,c,C,我想去掉问号。STDIN和STDOUT。但我似乎失败了 #define MAXLEN 256 #define widthh argv[2] // fixed void wordWrap(int col, char *providedStr);<- my algo for wordWrap int main(int argc, char **argv) { int infd, outfd, bytes; char buf[MAXLEN]; int num =
#define MAXLEN 256
#define widthh argv[2] // fixed
void wordWrap(int col, char *providedStr);<- my algo for wordWrap
int
main(int argc, char **argv) {
int infd, outfd, bytes;
char buf[MAXLEN];
int num = atoi(widthh);
for (int i = 1; i < argc; i++) {
infd = open(argv[i], O_RDONLY);
bytes = read(infd, buf, MAXLEN);
if (bytes > 0) {
wordWrap(num, buf);
}
printf("\n"); //just for adding new line to print new file moving forward
}
}
#定义MAXLEN 256
#定义宽度argv[2]//已修复
void wordWrap(int col,char*providedStr);0) {
字包装(num,buf);
}
printf(“\n”)//仅用于添加新行以打印前进的新文件
}
}
错误:了解更多有关宝马的信息
328i可靠性
评级。
?&??? <代码>//您可以根据需要设置最大值1024很好 #定义MAXLEN 1024 char buf[MAXLEN]=“”; 对于(int i=1;i
谢谢@Weather Vane你意识到如果(EOF)总是正确的吗
EOF
是-1
。当传递到printf()
时,字符串没有终止符,因此它可能会打印垃圾。尝试用char buf[MAXLEN]=“初始化它代码>或带有buf[字节]=0代码>在read.bro之后,我是c新手,我只是把它作为一个例子来展示我试图实现的目标。但值得注意的是,您打开每个文件时没有关闭前一个文件。@Weather Vane这是我现在实际使用的代码。然后呢?&???正在末尾打印,然后其他选项buf[bytes]=0
更好,因为字符串可能比前一个短。但是用MAXLEN-1
调用read
来腾出空间。@Weather Vane wait我很快就发布了答案,但是当我打印更多文件时,问题标记又回来了,buf[bytes]=0将是一个整数?否?好的,请阅读我之前的评论。请注意,'a'
也是一个整数。MAXLEN-1不会打印文件中的整个字符串。我理解你的意思,它不允许我初始化int buf[bytes]=0;我的大脑也不同意这样做。请解释请仔细阅读:buf[bytes]=0代码>。
// you can set max whatever you want for this purpose 1024 is good
#define MAXLEN 1024
char buf[MAXLEN] = "";
for (int i = 1; i < argc; i++) {
infd = open(argv[i], O_RDONLY);
bytes = read(infd, buf, MAXLEN - 1);
buf[bytes] = 0;
if (bytes > 0) {
wordWrap(num, buf);
}
printf("\n"); //just for adding new line to print new file moving forward
}