c - 在C中打印字符串文本不打印

标签 c windows windows-7 printing printf

我正在尝试将特定字符串打印到行式打印机。 我尝试运行此代码片段,但没有打印任何内容。我还在查看打印机的待处理作业列表,但运行代码时没有显示任何内容。

我可以很好地从 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/

相关文章:

apache - 如何在 Apache 2.4 (Windows 7) 上配置 SSL?

c - 读取用户输入,但必须与 C 中的字符串/小数/字符区分开

c - malloc、memset 和 free 的正确用法

c - 将一个 char 数组存储到另一个数组中 - c

windows - Xuggler 与 Windows 7 上的 Tomcat

c++ - Windows 上的堆损坏,但 Linux 上没有

c# - 如何防止应用程序被固定在 Windows 7 中?

c - 确保一个 cpu 在另一个 cpu 读取 "double"之前写入了 "double"?

windows - 如何在 Windows 中获取控制台的名称?

visual-studio - Visual Studio 2010 : the application data folder for visual studio cannot be created