Mail Archives: djgpp/1999/09/12/15:03:10
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 -