I am trying to extract the instance number from a DICOM image using dcmtk. The code is shown below:
DcmFileFormat fileformat;
OFCondition status = fileformat.loadFile(src_path);
if (status.good())
{
OFString instanceNumber=0;
if (fileformat.getDataset()->findAndGetOFString(DCM_InstanceNumber, instanceNumber).good())
{
std::cout << "instance Number N: " << instanceNumber << std::endl;
sprintf(instanceNum, "%s\n", instanceNumber);
printf("%s\n", instanceNum);
}
else
std::cerr << "Error: cannot access instance Number!" << std::endl;
}
else
std::cerr << "Error: cannot read DICOM file (" << status.text() << ")" << std::endl;
Now I got the instance number,but I want to copy the instance number into a char or string( for further programming).But as the number is an OFString,how do I convert it into the required datatype. Any thoughts?