我正在尝试将特定字符串打印到行式打印机。 我尝试运行此代码片段,但没有打印任何内容。我还在查看打印机的待处理作业列表,但运行代码时没有显示任何内容。
我可以很好地从 Word 打印文档,因此打印机可用。
有人可以暗示一下问题可能是什么吗?
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE* printer = 0;
if(( printer = fopen("lpt1", "a+")) == NULL)
{
puts("error opening printer");
}
char* text = "This is a test printing";
if ( (fprintf(printer, "%s" , text) ) < 0 ){
perror("Printing error");
}
fflush(printer);
fclose(printer);
return 0;
}
最佳答案
我认为您误解了该代码。您提交的代码将字符串“这是测试打印”写入同一目录中名为“lpt1”的文件中。
您可能想要的是写入类似“/dev/lpt1”的内容,并且您应该能够通过运行来测试它
echo "this is my printed text" >/dev/lpt1
关于c - 在C中打印字符串文本不打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18600131/