How to make loop in this function so I can carve my file?

The coding is about carving file from file_input1 but has to compare and same with my file_input2(which is a text file). Then only able to carve the file. I think I did my loop wrong. I don't know why I am getting wrong in the loop? Can anyone help me with it?

#include <stdio.h>

int main()
{
    FILE *file_input1 , *file_input2 , *file_output;
    
    unsigned char copied_char=0x0;
    unsigned char magicNumber1 = 0x0;
    unsigned char magicNumber2 = 0x0;
    unsigned char magicNumber3 = 0x0;
    unsigned char magicNumber4 = 0x0;
    unsigned char magicNumber5 = 0x0;
    unsigned char magicNumber6 = 0x0;
    unsigned char magicNumber7 = 0x0;
    unsigned char magicNumber8 = 0x0;
    long int curPos1 = 0L;
    long int curPos2 = 0L;
    long int sizeFile;
    long int offset = 0L;
    long int cluster = 0L;
    long int found = 0L;
    long int carvednum = 0L;
    long int EndCarveOffset = 205783912L;
        
    if((file_input1 = fopen("D:\\FileImage.001","rb")) == NULL)
        printf("File cannot be opened");
    
    if((file_input2 = fopen("D:\\offset_number.txt","rb")) == NULL)
        printf("Text File cannot be opened");

    if((file_output = fopen("D:\\RecoveredFile.pptx","wb")) == NULL)
        printf("Text File cannot be opened");
    
    fseek(file_input1, 0L, SEEK_END);
    sizeFile=ftell(file_input1);
    rewind(file_input1);
    
    printf("\nThe directory of the image : D:\\FileImage.001\n");
    
    printf("\nThe file size of FileImage.001 = %ld bytes",sizeFile);
    
while(fscanf(file_input2 , "%ld" , &carvednum)==1)
{
        printf("%ld\n",carvednum);
        cluster = carvednum / 512;
        printf("%ld\n",cluster);
}

while (offset <=sizeFile)
{
    offset = carvednum;
        if (fseek(file_input1,carvednum,SEEK_SET)==1)
        {
        offset = carvednum;
        }
    copied_char = fgetc(file_input1);
    fputc(copied_char,file_output);
    offset++;
}
    
    fclose(file_input1);
    fclose(file_input2);
    fclose(file_output);
    printf("\n\nPress any key to exit ...");
    

getchar();
}