LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-16-2004, 01:32 AM   #1
reddazz
LQ Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 77
stdprn in c program


Ok, I hsve decided to learn C, everything seems to be going okay, but I have hit a bit of a stumbling block. I am working on an example from a book I am using and I get the following error when I try to compile the program,

print_it.c: In function `main':
print_it.c:32: error: `stdprn' undeclared (first use in this function)
print_it.c:32: error: (Each undeclared identifier is reported only once
print_it.c:32: error: for each function it appears in.)
print_it.c: In function `do_heading':
print_it.c:41: error: `page' undeclared (first use in this function)
print_it.c:44: error: `stdprn' undeclared (first use in this function)

here is the code for the program,

#include <stdio.h>
#include <stdlib.h>
int main (int argv, char *argc[])
{
void do_heading (char *filename);

int line = 0, page = 0;

char buffer[256];
FILE *fp;

if (argv < 2)
{
fprint (stderr, "\nProper Usage is: ");
fprint (stderr, "\n\nprint_it filename.ext\n");
return (1);
}

if ((fp = fopen(argc[1], "r")) == NULL)
{
fprintf (stderr, "Error opening file, %s!", argc[1]);
return (1);
}
page = 0;
line = 1;
do_heading (argc[1]);

while (fgets (buffer, 256, fp) != NULL)
{
if (line % 55 == 0)
do_heading (argc[1]);
fprintf (stdprn, "%4d:\t%s", line++, buffer);
}

fprint (stdprn, "\f");
fclose (fp);
return 0;
}
void do_heading (char *filename)
{
page++;

if (page > 1)
fprint (stdprn, "\f");
fprintf (stdprn, "Page: %d, %s\n\n", page, filename);
}

I know my problem has to do with "stdprn" but how do I fix this.
 
Old 10-16-2004, 09:36 AM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
DOS compilers supplied a stdprn stream; linux does not.
 
Old 10-16-2004, 10:52 AM   #3
reddazz
LQ Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Original Poster
Rep: Reputation: 77
I see, is there a way to adjust this code to run on Linux without using stdprn?
 
Old 10-18-2004, 11:30 AM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Try something like this:
Code:
#include <stdio.h>

/* ... */

main ()
{
    FILE *prn;

    /* ... */

    prn = fopen("/dev/lp0", "w");
    if (prn == NULL) {
        perror("Opening printer");
        return 1;
    }

    /* ... */

    fprintf (prn, "%4d:\t%s", line++, buffer);

    /* more  fprintf (prn,  .....*/
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sms program and database in linux web program in windows.. does not see each other.. keikun_naruchan Programming 0 07-06-2005 01:40 AM
Total recovery: Which program? ghost4linux, YaST2? Best drive imaging program? lagu2653 Linux - Software 1 06-20-2005 01:44 PM
Key bindings program (custom pasting, program execution, etc.) jrdioko Linux - Software 2 02-05-2005 09:09 PM
Gtk-Warning but program still works... I close konsole, program closes Laptop2250 Linux - Software 2 11-14-2003 11:18 PM
Viewing program messages when program isn't run from command line? Locura Linux - Software 1 09-27-2003 08:19 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration