getline() and segmentation fault

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?

Thanks for your help.


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
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');
		}
		else if (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().
Thanks helios, that worked.
Topic archived. No new replies allowed.