Write a 'C' Program to do the following a) Create a text file 'input.txt' b) Print the contents of file in reverse order


#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 do the following a) Create a text file 'input.txt' b) Print the contents of file in reverse order  Write a 'C' Program to do the following  a) Create a text file 'input.txt'  b) Print the contents of file in reverse order Reviewed by on April 24, 2015 Rating: 5
Powered by Blogger.