Kenneth Brody
6/14/2011 3:16:00 PM
On 6/13/2011 6:15 PM, BartC wrote:
> "Robert Bralic" <robert.bralic@si.t-com.hr> wrote in message
> news:it4jp9$gth$1@ss408.t-com.hr...
>> #include<stdio.h>
>>
>>
>> int main(int argc, char *argv[]){
>> FILE *fp;
>> fp=fopen("LPT1:", "w");
>> fprintf(fp,"Hello World");
>> return 1;
>> }
>
> Looks like Windows.
>
> In that case, first establish that you have a working printer attached, by
> typing this in a console:
>
> copy filename LPT1:
>
> (with and without the colon, and where filename refers to an existing text
> file). If that works then you can go back to the code.
>
> If the copy command doesn't work, there could be a million reasons why not.
While our assumption that the OP is on Windows is probably correct,
everything else is just guesswork until he defines "doesn't work".
Also, you are assuming that the "copy" command treats "LPT1:" the same as
the C runtime library. This is not necessarily the case. For example, this
command displays the file in the console window:
copy usenet.c con
yet this does not:
cp usenet.c con
(Where "cp" is a utility I have which performs the same as the *nix "cp"
command.) In this case, I get the error:
cp: Error copying file usenet.c to con: The handle is invalid.
Which, strangely enough, probably means that the open succeeded, but the
write failed. The OP needs to check the return from fprintf() as well as
fopen().
--
Kenneth Brody