Featured Post

Monday, November 7, 2016

C program to merge two files into third file



main()
{
     FILE *fp1,*fp2,*fp3;

     char c;

     fp1=fopen("sample.txt","r");

     fp2=fopen("hello.txt","r");

     fp3=fopen("myfile.txt","a");

     if(fp1==NULL)
     {
         printf("\n file does not exist");

         exit(1);
      }
     if(fp2==NULL)
      {
          printf("\n file does not exist");
       }
      if(fp3==NULL)
      {
          printf("\n file cannot be created");
       }
    while((c=getc(fp1))!=EOF)
    {
        putc(c,fp3);
     }
    while((c=getc(fp2))!=EOF)
    {
        putc(c,fp3);
     }
   printf("\n third file successfully created");
  }

OUTPUT:
               third file successfully created

C program to count number of characters, words and lines in a given file

C program to create a file and display file contents on to the screen , file handling in c, random access to a file, random handling in file, random file handling in c, random access to a file in C, getc(), putc(), fopen(), fclose(),getw(),putw(), c program to display file contents on to the screen. different typed of modes in files. differentiate between r and r+ mode, w and w+ mode , a and a+ mode.EOF, end of the file.

No comments:

Post a Comment