'Seg fault for line fscanf(f,"%[^\n]%*c",temp);

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int GET (FILE* f, char act[100],int check)
{
    if(check==0)
    {
        return 0;
        
    }
    
    char temp[20];
    fscanf(f,"%[^\n]%*c",temp);
    
    
    
    if(feof(f))
    {
        strcpy(act,NULL);
        return 0;
    }
    
    strcpy(act,temp);
    act[21]='\0';
    return 0;

}
int main(int argc, char** argv)
{
    FILE* fa = fopen(argv[1],"r");
    FILE* fb = fopen(argv[2],"r");

    FILE* f1 = fopen(argv[3],"w");
    char act1[100];
    char act2[100];
    int flagA=1;
    int flagB=1;

    
   
    
    while(1)
    {
        GET(fa,act1,flagA);
        GET(fb,act2,flagB);
        if(strcmp(act1,NULL)==0 && strcmp(act1,NULL)==0)
        {
            break;
        }
        int a = strcmp(act1,act2);
        if(a==0)
        {
            flagA=1;
            flagB =1;
            fprintf(f1,"%s\n%s\n",act1,act2);
        }
        else if(a>0)
        {
            flagA=0;
            flagB =1;
            fprintf(f1,"%s\n",act2);
        }
        else
        {
            flagA=1;
            flagB =0;
            fprintf(f1,"%s\n",act1);
        }
        
    }
    
    
    fclose(fa);
    fclose(fb);
    fclose(f1);
    
    return 0;
}

The program is supposed to take two files each containing a sorted list of names and combine them into one file, with the names sorted. I'm getting a segmentation fault on the line

fscanf(f,"%[^\n]%*c",temp); It worked perfectly when I ran a much simpler program to take names from a file and print it to another file. The file format is Name1 Name2 Name3 . . . So on. Each name is not more than 15 characters long.

Any help would be greatly appreciated. Thank You.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source