I am able to expand a given .bmp horizontally but the code for vertical expansion is not working. Here is my code for vertical expansion. 

// resize vertically

//move pointer to start of scanline of outptr
        fseek(outptr,  -3 * (bi2.biWidth + padding), SEEK_CUR);
        
        fgetpos (outptr,&pos);
        
        //an array of RGBTRIPLE to store one scanline
        RGBTRIPLE triple[bi2.biWidth + padding]; 
        
        //reading the already written first line    
        for (int p = 0 ; p < bi2.biWidth + padding; p++)
        { 
            fread(&triple[p], sizeof(RGBTRIPLE), 1, outptr); 
        }
        fgetpos (outptr,&pos);           
        
        //writing the copied array to outptr
        for (int k = 0 ; k < n; k++)
        {             
            for (int p = 0 ; p < bi2.biWidth + padding; p++)
             
                fwrite(&triple[p], sizeof(RGBTRIPLE), 1, outptr);   
                        
        }      
This is written after the first scanline is copies correctly from input bmp. Used gdb to find the values in triple[0],triple[1].....but all those are garbage. Also if i check the position of pointer in outptr using fgetpos (outptr,&pos), its not changing.