C program to copy the contents of one file to another

#include<stdio.h> #include<conio.h> void main()
{
FILE *fs,*ft;
char ch,fname1[20],fname2[20]; printf("\n Enter source file name:"); gets(fname1);
printf("\n Enter destination file name:"); gets(fname2);
fs=fopen(fname1,"r"); ft=fopen(fname2,"w"); if(fs==NULL||ft==NULL)
{
printf("unable to open"); exit(0);
}
do
{
ch=fgetc(fs); fputc(ch,ft);
}while(ch!=EOF); fcloseall();
printf("\nFile copy operation performed successfully");
}
Output
Enter source file name: 1.c Enter destination file name: 2.c
File copy operation performed successfully

Comments

  1. Bro Palindrome add cheyandi bto

    ReplyDelete
  2. #include
    #include
    int main()
    {
    char a[20];
    int begin,end,mid,len=0,i=0;
    printf("\n Enter the String = ");
    gets(a);
    while (a[i] != '\0')
    {
    len++;
    i++;
    }
    end =len -1;
    mid = len/2;
    for(begin =0; begin<mid;begin++)
    {
    if (a[begin] != a[end])
    {
    printf("\nNOT PALINDROME\n");
    break;
    }
    end--;
    }
    if (begin == mid)
    printf("\nPALINDROME\n");
    return 0;
    }
    /*
    Output:-
    Enter the String = malayalam
    PALINDROME
    */

    ReplyDelete

Post a Comment

Popular posts from this blog

Division of two complex numbers

Student marks by using structures