delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/09/12/15:03:10

From: "Damian Yerrick" <mail DOT me DOT at DOT your DOT own DOT risk AT pineight DOT 8m DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Printing Problems
Date: Sun, 12 Sep 1999 11:40:23 -0500
Organization: Rose-Hulman Institute of Technology
Lines: 71
Message-ID: <7rgl5a$93i$1@solomon.cs.rose-hulman.edu>
References: <7rgc8q$e1c$2 AT perki DOT connect DOT com DOT au>
NNTP-Posting-Host: yerricde.laptop.rose-hulman.edu
X-Trace: solomon.cs.rose-hulman.edu 937154538 9330 137.112.205.146 (12 Sep 1999 16:42:18 GMT)
X-Complaints-To: news AT cs DOT rose-hulman DOT edu
NNTP-Posting-Date: 12 Sep 1999 16:42:18 GMT
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2314.1300
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Tim Chmielewski <tchuma AT sympac DOT com DOT au> wrote in message
news:7rgc8q$e1c$2 AT perki DOT connect DOT com DOT au...
> I'm having a problem with printing out the results of this program to
> the printer.

What's the error message?

>
> It prints :
>
> Tattslotto number generator.
> (garbage)

I've been having trouble with garbage appearing when I start
a program under Win98 too.

>8

> main()

really should be int main(void) or int main(int argc, char **argv)
to comply with ANSI C.

> {
>
> FILE *fp;
> int tempint = 0;

Delete holdint.

>
> if((fp = fopen("prn","w"))==NULL)

Is it opening a file called PRN? Try printing to the FILE* called stdprn
stdprn is already open to point to LPT1 when you start your C program.

>      {
>      puts("Cannot access the printer");
>      exit(1);
>      }
>
> fputs("Tattslotto number generator.\n", fp);
> srand(time(NULL));
>
>    for (int i = 1; i <= 4; i++) {
>      for (int j = 1; j <= 6; j++) {
>         tempint = 1 + (rand() % 45);

>         memset(holdint, tempint, 2);
>         strcat(holdint, " ");
>         fputs(holdint ,fp);

This is your problem: You are trying to print ASCII characters.
Try this line instead of the above three:

fprintf(fp, "%d ", tempint);

>      }
>      fputs("\n", fp);
>    }
>
> fclose(fp);
> return 0;
> }
>
>
> Thanks.
>


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019