Why this doesen't work...?

R

Robert Bralic

#include<stdio.h>


int main(int argc, char *argv[]){
FILE *fp;
fp=fopen("LPT1:", "w");
fprintf(fp,"Hello World");
return 1;
}

Thanks in advance, Robert...;)
(e-mail address removed)-com.hr




__________ Information from ESET NOD32 Antivirus, version of virus signature database 6201 (20110612) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
E

Eric Sosman

#include<stdio.h>


int main(int argc, char *argv[]){
FILE *fp;
fp=fopen("LPT1:", "w");

You should check here to see whether fopen() succeeded. If
it failed, fp will be NULL indicating that "LPT1:" could not be
opened (for whatever reason). If fp is non-NULL, fopen() succeeded
and you can go ahead and use it.
fprintf(fp,"Hello World");

On some systems, a "line of text" isn't complete until you've
written a newline character at the end.
return 1;

On most systems, a non-zero exit status means "I failed."

There are other, probably less important flaws in the code,
but I'm not going to bother with them until and unless you explain
just what you mean by "doesen't work." In what way does it fail
to work? What were you expecting the program to do, and what did
it do instead?
 
J

J. J. Farrell

Robert said:
#include<stdio.h>


int main(int argc, char *argv[]){
FILE *fp;
fp=fopen("LPT1:", "w");
fprintf(fp,"Hello World");
return 1;
}

Thanks in advance, Robert...;)
(e-mail address removed)-com.hr

Works fine for me. Perhaps you should tell us in what way it doesn't
work for you.
 
B

BartC

Robert Bralic said:
#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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top