Write a 'C' Program to append the contents of one file at the end of another file.


#include

void main()
{
    FILE *fp;
    char str[80],file[80],ch;
    char i = 0;
    clrscr();
    printf("ENTER FILE NAME::>\n");
    scanf("%s",file);
    fp = fopen(file,"r");
    if(fp == NULL)
    {
        printf("UNABLE TO OPEN THE FILE.");
        getch();
        exit(0);
    }
    printf("\nCONTENTS OF THE FILE::>\n");
    while(1)
    {
        ch = fgetc(fp);
        if(ch == EOF)
            break;
        printf("%c",ch);
    }
    fclose(fp);
    fp = fopen(file,"r");
    printf("\nCONTENTS OF FILE IN REVERSE ORDER::>\n");
    while(1)
    {
        ch = fgetc(fp);
        if(ch == EOF)
            break;
        if(ch == '\n' || ch == ' ')
        {
            str[i] = '\0';
            strrev(str);
            printf("%s",str);
            i = 0;
        }
        else
            str[i++] = ch;
    }
    fclose(fp);
    getch();
}
Write a 'C' Program to append the contents of one file at the end of another file. Write a 'C' Program to append the contents of one file at the end of another file. Reviewed by on April 24, 2015 Rating: 5
Powered by Blogger.