0
#include<stdio.h>

#define CR 13
#define LF 10

int main()
{
    FILE *tg;
    FILE *th;
    FILE *printer;
    int i,a;
    char input[20];
    char file[100];
    char input2[20];
    char file2[100];
    
    printf("Enter the file name for reading : ");
    scanf("%s",input);
    th = fopen(input,"r");
    printer = fopen("PRN","w");
    do
    {
        i=fgets(file,100,th);
        putc(i,printer);
        printf("\n\n%s",file);
    }while(i != EOF);
    printf("Enter a file for writing to : ");
    scanf("%s",input2);
    tg = fopen(input2,"w");
    char c;
    printf("Write something : ");
    do
    {
        c=getch();
        putc(c,tg);
        if( c==CR )
        {
            putchar(LF);
        }
        putchar(c);
        
    }while(c != '~');
    getchar();
    fclose(tg);
    fclose(th);
}

What is the problem with the above programme..
when i open a file for reading it just shows the last few words?

help .....

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Ancient Dragon
1

line 20: Whether that line succeeds in connecting to your printer will depend on the printer and operating system. I have an HP Officejet laser printer on USB (Windows 7) and that line failes to open it.

line 24: you are sending a binary number to the printer. Printers do not know how to print them. The number will have to be converted to text before sending it to the printer.

char text[20];
sprintf(text,"%d", i);
fputs(text, printer);

Edited by Ancient Dragon: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.