Q:

Sorting from two text files c

I have two sorted sequences one on data1.text another one in data2.txt both contains 20 sortet numbers. I need to create code sort.c that reads numbers from both txts and at the same time compares them and outputs smaller one in sort.txt , so it is kinnda merging sort)
that is my code:       
#include <stdio.h>
int main(int argc,char *argv1[],char *argv2[],char *argv3[])
    {

        char *f1 = argv1[1];// taking filename1 from args
        char *f2 = argv2[1];// taking filename2 from args
        char *f3 = argv3[1];// taking filename2 from args
        FILE *fp1,*fp2,*fp3;

        fp1 = fopen(f1,"r");
        fp2 = fopen(f2,"r");
        fp3 = fopen(f2,"w");// sort.txt file so 'w'
        int num1,num2;
        fscanf (fp1, "%d", &num1);
        fscanf (fp2, "%d", &num2);
        while (!feof(fp1) && !feof(fp2)) {
        if (num1<num2)
            {
                fprintf(fp3,"%d\t",num1);// print num 1
                fscanf (fp1, "%d", &num1);  // read num1
            }
            else{
                fprintf(fp3,"%d\t",num2);
                fscanf (fp2, "%d", &num2);  // read num2
            }
        }

         if (!feof(fp1))
         {
            while (!feof(fp1))
            {
                fprintf(fp3,"%d\t",num1);// print num 1
                fscanf (fp1, "%d", &num1);  // read num1
            }
         }
            else
            {

                while (!feof(fp2))
                {
                    fprintf(fp3,"%d\t",num2);
                    fscanf (fp2, "%d", &num2);  // read num2
                }
            }

        fclose(fp1);// closing file f1
        fclose(fp2);// closing file f2
        fclose(fp3);// closing file f2

        return 0;
}

it shows segmentation fault =(

A:

Your main is wrong. Should be int main(int argc, char **argv).
Then instead of
    char *f1 = argv1[1];// taking filename1 from args
    char *f2 = argv2[1];// taking filename2 from args
    char *f3 = argv3[1];// taking filename2 from args

something like 
    char *f1 = argv[1];// taking filename1 from args
    char *f2 = argv[2];// taking filename2 from args
    char *f3 = argv[3];// taking filename2 from args

but before these lines you should check argc for correct number of arguments.
You probably meant fp3 = fopen(f3,"w"); instead of fp3 = fopen(f2,"w");.

