|
From: Carlos d. M. <cg...@wo...> - 2002-10-09 10:36:47
|
In C you must define the variables at the beginning of the function
body, not at the half, you define *fp in the middle of the function.
Samuel Keding escribi=F3:
> I am trying to learn how to send something to a
> printer. I try to compile this .c file and dev
> complains that there is a parsh error before '*' (on
> the line where I declare FILE *fp =3D
> fopen("LPT1","wt"); and then gives another error
> because it thanks fp is a function.) Can anyone tell
> me what I'm doing wrong in this code?
>
> #include <conio.h>
>
> char PrintBuf[5000]; // make it large enough!
>
> int printer(const char *Format,...) //user defined
> function
> {
> char *Ptr =3D PrintBuf+lstrlen(PrintBuf);
Put FILE *fp; here. And where you have defined it, only perform the
opening.
>
> va_list arglist;
>
> va_start(arglist,Format);
> vsprintf(Ptr,Format,arglist);
> va_end(arglist);
> return printf(Ptr);
> }
>
> void main()
> {
> PrintBuf[0] =3D 0;
>
> // your program runs here......
> // just use printer() instead of printf.
> // It will print text to screen and into the buffer
> // example:
> printer("\t\t\tS K DATABASE SOLUTIONS\n\n");
> printer("\t\t\t=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-\n\n");
> printer("Employee ID: %d\n",1001);
> printer("Employee Name:%s\n","Shashi");
> printer("Employee Pay:%f\n",1000.75);
> printer("-=3D=3D=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-");
>
> // Now print the buffer to the printer
>
> FILE *fp =3D fopen("LPT1","wt");
>
> if(fp)
> {
> fwrite(PrintBuf,1,lstrlen(PrintBuf),fp);
> fputc('\f',fp); // add a formfeed for pageprinters
> fclose(fp);
> }
>
> return 0;
> }
>
> __________________________________________________
> Do you Yahoo!?
> Faith Hill - Exclusive Performances, Videos & More
> http://faith.yahoo.com
>
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|