#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 .....

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);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.