Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Homework HelpRSS Feeds

Program to merge and display 2 files

Posted By: Easy Tutor     Category: C Programming     Views: 4607

Write a program to merge and display files having integer numbers stored in it.

Code for Program to merge and display 2 files in C Programming

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


void main(int argc,char *argv[]){
     FILE *fmrg,*fd1,*fd2;
     int data1[]={1,3,9,15,18,20,30};
     int data2[]={2,3,5,8,9,23,28};
     int i,data,tmp1,tmp2;

     clrscr();
     fd1 = fopen("data1.txt","w");
     for(i=0;i<7;i++)
    putw(data1[i],fd1);
     fclose(fd1);

     fd2 = fopen("data2.txt","w");
     for(i=0;i<7;i++)
    putw(data2[i],fd2);
     fclose(fd2);

     fmrg = fopen(argv[1],"w");
     fd1  = fopen("data1.txt","r");
     fd2  = fopen("data2.txt","r");
     //merge logicwhile(!feof(fd1)){
    data = getw(fd1);
    putw(data,fmrg);
     }
     while(!feof(fd2)){
    data = getw(fd2);
    putw(data,fmrg);
     }
     fclose(fd1);
     fclose(fd2);
     fclose(fmrg);

     printf("\n\n***After Merging Files***\n\n");
     fmrg = fopen(argv[1],"r");
     while(!feof(fmrg))
     {
    data = getw(fmrg);
    printf("%5d",data);
     }
     fclose(fmrg);

     /*     //sort logic     fd1 = fopen(argv[1],"r");     fd2 = fopen(argv[1],"r");     while(!feof(fd1)){      fseek(fd1,2L,SEEK_CUR);      tmp1 = getw(fd1);      while(!feof(fd2)){         fseek(fd2,2L,SEEK_CUR);         tmp2 = getw(fd2);         if(tmp1 > tmp2)     */
getch();
}
  
Share: 


Didn't find what you were looking for? Find more on Program to merge and display 2 files Or get search suggestion and latest updates.

Easy Tutor
Easy Tutor author of Program to merge and display 2 files is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Thanks,
Happy Programming :)

 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!