Passing and writing an array of strings

What I am looking for help with is char Header in the code below (Note this is a short sample code). The string length is unknown until I read the structure pInfoImage in the CamGetImage function. The number of stings will need to be equal to numFrames. How can I dynamically allocate Header so it will be the correct dimensions for the string length/number of frames and then return it to write it to a file?

Note that I am new but have tried using new and pointers, strings, vectors, ostringstream, and stacks, but have not been able to get it working correctly. I apparently need it spelled out for me...

Any and all help is appreciated. Thanks!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
VSIDRIVER_API	int CamSaveImageSetInC(const int numFrames, char fname[])
{
        //Memory Allocation for the Header
	char Header[120][120];

        // Opens a file and writes a file header
	HRESULT hr = CamStartImageSet(numFrames, fname);
	
	if(hr!=0)
	{
		CamEndImageSet();
		return hr;
	}
        
        // This loop records header info for each frame
	for (int n = 0; n < numFrames; n++)
	{
		HRESULT hr = CamGetImageSet(Header[n]);
		
		camStatus.numCounts = n+1;
	}

	//Takes image and header sets and writes them to separate files
	if (hr == 0)
	{
		hr = fwrite(Header, 2, numFrames*120, Hd);
	};
	
        // Closes the files
	return CamEndImageSet();;
}

VSIDRIVER_API	int CamGetImageSet(char Header[])
{
	// A portion of the code I removed stored the info in pMemBuffer
	InfoImageStruct* pInfoImage	= ((InfoImageStruct*)m_sSharedMem[INF_SHARED_MEM].pMemBuffer);
	
        // Here is how I currently am able to write to Header
	sprintf_s(Header, 120, "Preset:%d; ITime:%7.3f; ImageTime:%I64u; Count:%I64u; T:%.1f; T1:%.1f; T2:%.1f; T3:%.1f; T4:%.1f\n",  
	  pInfoImage->wMultiItNumber, //preset
	  pInfoImage->fIntegrationTime,
	  pInfoImage->qwImageTime,
	  pInfoImage->qwImageCounter,
	  pInfoImage->fDetectorTemp,
	  pInfoImage->fSensorTemp[0],
	  pInfoImage->fSensorTemp[1],
	  pInfoImage->fSensorTemp[2],
	  pInfoImage->fSensorTemp[3]);

	return 0;
}
Topic archived. No new replies allowed.