I was wondering what the best way was to copy a struct. Most of the info I was able to find online was about just copying the pointer to the struct. But what if I wanted to make a complete copy of a struct? One that I can modify without affecting the original?
This is sort of related to PSET4 resize. I wanted to copy the BITMAPFILEHEADER and BITMAPINFOHEADER so that I could pass that into the new file with changed values without affecting the original. What I ended up doing was just creating a new struct and copying the values one by one. Is there a function or something that allows me to quickly make a copy?
BTW questions similar to this one got responses saying you don't need to deal with structs for this PSET, just make an array, I get that, but I would like to know how to copy a struct regardless.
// update outfile BITMAPINFOHEADER BITMAPINFOHEADER new_bi; new_bi.biSize = bi.biSize; new_bi.biWidth = n * bi.biWidth; new_bi.biHeight = n * bi.biHeight; new_bi.biPlanes = bi.biPlanes; new_bi.biBitCount = bi.biBitCount; new_bi.biCompression = bi.biCompression; // determine padding for new scanlines int new_padding = (4 - (new_bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4; new_bi.biSizeImage = (((new_bi.biWidth * sizeof(RGBTRIPLE)) + new_padding) * -(new_bi.biHeight)); new_bi.biXPelsPerMeter = bi.biXPelsPerMeter; new_bi.biYPelsPerMeter = bi.biYPelsPerMeter; new_bi.biClrUsed = bi.biClrUsed; new_bi.biClrImportant = bi.biClrImportant; // update outfile BITMAPFILEHEADER BITMAPFILEHEADER new_bf; new_bf.bfType = bf.bfType; new_bf.bfSize = (new_bi.biSizeImage + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)); new_bf.bfReserved1 = bf.bfReserved1; new_bf.bfReserved2 = bf.bfReserved2; new_bf.bfOffBits = bf.bfOffBits;