Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在C中打印字符串文本不会打印_C_Windows_Windows 7_Printing_Printf - Fatal编程技术网

在C中打印字符串文本不会打印

在C中打印字符串文本不会打印,c,windows,windows-7,printing,printf,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("er

我正在尝试将特定字符串打印到行打印机。 我试图运行此代码段,但没有输出任何内容。我还查看了打印机的挂起作业列表,在运行代码时没有显示任何内容

我可以从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;
}
#包括
#包括
int main()
{
文件*打印机=0;
如果((打印机=fopen(“lpt1”,“a+”)==NULL)
{
puts(“打开打印机时出错”);
}
char*text=“这是测试打印”;
如果((fprintf(打印机,“%s”,文本))<0){
perror(“打印错误”);
} 
fflush(打印机);
fclose(打印机);
返回0;
}

我想你误解了那个代码。您提交的代码将字符串“thisatestprinting”写入同一目录中名为“lpt1”的文件中

您可能想要的是写出“/dev/lpt1”之类的内容,您应该能够通过运行

echo "this is my printed text" >/dev/lpt1

不,您不能在Windows上使用
fopen()
写入打印机端口。最接近的方法是生成
cmd.exe
,并使用来打印所需内容。您可以先将所需内容写入临时文件,然后让
print
为您打印。

it
lpt1
某种特殊文件?不,它是并口。它与COM1 COM2等一起显示在设备管理器上。我认为大多数人输出到文件,然后从Windows打印出来。但要一步完成,您需要打开一个程序进行输出,而不是打开一个文件。这里解释如下:假设您的文本实际到达打印机,页面打印机(大多数现代打印机都是这样)在页面完成之前不会打印任何内容。尝试在字符串末尾添加一个换行符(
'\f'
'\x0c'
)。这可能会有所帮助:这在windows中。所以没有/dev。对不起,我应该提到它。