Changing a Record

I'm having trouble with a function I'm trying to add to my program..

It's working with the output, but it's deleting the entire record from the structure when I'm just trying to replace a single piece of it (the price) with a new value...Any ideas as to why this is happening?

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
52
53
54
55
56
57
58
void changePrice(int& counter, listingInfo* &newListing, listingInfo* &top)
{
	const string CHANGES = "CHANGES.TXT";
	const int TEMPSTORAGE = 99999;
	ifstream changes_file;
	
	listingInfo* here;
        listingInfo* prev;
	
	string line;
	int changes_count = 0;
	int tempMLS;
	double tempPrice;
	double priceReplace;
	
	changes_file.open(CHANGES.c_str());
		
	while ( getline(changes_file, line) && line.length() )
	{	
		istringstream changes_line(line);
				
       	        changes_line >> tempMLS;
       	        changes_line >> tempPrice; 
        
		if ( here->mls_number == tempMLS ) 
		{
			here = top;
			top = here->link;
			here->price = here->price - tempPrice;
	        	        
	                cout << here->mls_number << "       " << here->price << endl;
		}
	
		else 
		{
	    	        prev = top;
	                here = top->link;
	
	                while ( (here != NULL) && (here->mls_number != tempMLS) ) 
			{   
				prev = here;
	           	        here = here->link;
	       	        }
	
	                  if (here != NULL) 
			 {
	         	         prev->link = here->link;
	                         here->price = here->price - tempPrice;	            
	            
	                         cout << here->mls_number << "       " << here->price << endl;
	                 }
	
		}
		
	}
	
    changes_file.close();
}
I believe you will be getting a seg fault on line 25 because the pointer 'here' is initially not pointing at anything valid.


Also why are you doing this:
listingInfo *&newListing
Topic archived. No new replies allowed.