My problem is that this part of my code keeps returning a segmentation fault at "currfile.getline(value, 256, '\n');".
What can i do to fix this or avoid it? My goal is to read a line up until a white space is read and then skip a couple lines and then read the other values... why do i keep getting that segmentation fault?
if (currfile.is_open())//will return false if current file failed to open
{
char comcheck;//comment check, to check for comments
while (currfile.good())//while current file is still "good"
{
comcheck = currfile.peek();//get first character from file
if (comcheck == '#')//checking for commented area
{
currfile.ignore(256, '\n');
}
elseif (comcheck == '\n')//checking for blank line
{
currfile.ignore(256, '\n');
}
else
{
char* pmeter;
char* value;
currfile.getline(pmeter, 256, ' ');
cout << "\n" << pmeter << "\n";
currfile.ignore(2, '\n');
currfile.getline(value, 256, '\n');
cout << "\n" << value << "\n";
}
}
}
Neither value nor pmeter point to anything valid at the time getline() is called.
Either declare them as stack arrays (e.g. char pmeter[256];), or assign them a pointer to a heap array before the call to getline().