Friday 7 September 2012

Program for reversing each line and copying into a New File

#include <stdio.h>
#include <conio.h>
#include <string.h>

void main(int argc, char *argv[])
{
    FILE *fp1,*fp2;
    char st[125];

    clrscr();
    printf("Program for reversing each line and "
        " copying into a New File\n");
    printf("The number of arguments passed to this "
        "program are %d\n",argc);
    fp1 = fopen(argv[1],"rb");
    if (fp1 == NULL )
      {
        printf("First Argument File Opening Error\n");
        exit(0);
      }
    fp2 = fopen(argv[2],"wb");
    if (fp2 == NULL )
      {
        printf("Second Argument File Opening Error\n");
        exit(0);
      }
    printf("\nThe file %s is opened and each line is reversed "
            "and copied onto the file %s\n", argv[1],argv[2]);
    while (!feof(fp1))
       {
        fgets(st,120,fp1);
        strrev(st);
        fputs(st,fp2);
       }
    fcloseall();
    printf("\nPress any key to end...");
    getch();
}

No comments:

Post a Comment