<Bad Ptr> error

Hi everyone,

I have the following loop that reads line by line from a file:
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
	
string node_string="";
char node_char_array[20];
stringstream ss;
char line_buf[100]; 
...
while(fgets(line_buf,100,fp)) //while we read lines from the file, while loop will last
				{
					int i=0;
					int prov; 
					if(line_buf[0]==' ') 
					continue;
					else{
						ss.clear();
						node_string="";
						sscanf(line_buf,"%s",node_char_array); //read the coordinates from the line_buf
						ss<<node_char_array;
						ss>>node_string;
						
						(*words_array).SetNodeLabel(node_string);
						//overload operator =
						dict[node_string.c_str()]=words_array;
						
						words_array++;
					}
						
				}

It reads well until all of a sudden node_string gets a <Bad_Ptr> value and the code throws a run time error in the ss>>node_string line. I have checked, the node_char_array has the word value and the ss has values too.
What can possibly happen for a string variable all of a sudden to become bad pointer in the middle of the code execution. It is weird because in the beginning the string variable works just fine.

Thanks a lot!
This approach makes no sense to me at all. It is a C++ program. Try using getline instead of gets.If line_buf is 100 long and node_char_array is only 20 how do you know that you aren't attempting to write too much data into the output string? Use std::string and C++ STL functions in all cases for consistency. Your use of stringstream seems very inappropriate since you could have used std::string in the first place along with its assignment operator and member functions for copying and making substrings.

if you would like some help making these changes, please post the file contents so that we can see what you are working with.
This is how the file looks like. I need only the first word to be read into a string. I don't need the License lines. Please help me on this and which c++ functions I should use instead of the c ones I have in the code. Thanks a lot!

1 This software and database is being provided to you, the LICENSEE, by
2 Princeton University under the following license. By obtaining, using
3 and/or copying this software and database, you agree that you have
4 read, understood, and will comply with these terms and conditions.:
5
6 Permission to use, copy, modify and distribute this software and
7 database and its documentation for any purpose and without fee or
8 royalty is hereby granted, provided that you agree to comply with
9 the following copyright notice and statements, including the disclaimer,
10 and that the same appear on ALL copies of the software, database and
11 documentation, including modifications that you make for internal
12 use or for distribution.
13
14 WordNet 3.0 Copyright 2006 by Princeton University. All rights reserved.
15
16 THIS SOFTWARE AND DATABASE IS PROVIDED "AS IS" AND PRINCETON
17 UNIVERSITY MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
18 IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PRINCETON
19 UNIVERSITY MAKES NO REPRESENTATIONS OR WARRANTIES OF MERCHANT-
20 ABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE
21 OF THE LICENSED SOFTWARE, DATABASE OR DOCUMENTATION WILL NOT
22 INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR
23 OTHER RIGHTS.
24
25 The name of Princeton University or Princeton may not be used in
26 advertising or publicity pertaining to distribution of the software
27 and/or database. Title to copyright in this software, database and
28 any associated documentation shall at all times remain with
29 Princeton University and LICENSEE agrees to preserve same.
'hood n 1 2 @ ; 1 0 08641944
's_gravenhage n 1 2 @ #p 1 0 08950407
.22 n 1 2 @ ~ 1 0 04502851
0 n 1 1 @ 1 1 13742358
1 n 1 2 @ ~ 1 1 13742573
1-dodecanol n 1 1 @ 1 0 14930670
1-hitter n 1 1 @ 1 0 00475142
10 n 1 1 @ 1 1 13746512
100 n 1 1 @ 1 1 13750415
1000 n 1 2 @ ~ 1 0 13750844
10000 n 1 1 @ 1 0 13751265
100000 n 1 1 @ 1 1 13751404
1000000 n 1 1 @ 1 0 13751533
1000000000 n 1 3 @ ~ ; 1 0 13751829
1000000000000 n 2 2 @ ; 2 0 13752443 13752172
11 n 1 1 @ 1 1 13746672
11-plus n 1 2 @ ; 1 0 00637145
11_november n 1 2 @ #p 1 0 15185837
12 n 1 2 @ ~ 1 1 13746785
12-tone_music n 1 1 @ 1 0 07057539
12-tone_system n 1 1 @ 1 0 07057539
120 n 1 1 @ 1 0 13750574
13 n 1 1 @ 1 0 13747199
14 n 1 1 @ 1 1 13747348
144 n 1 1 @ 1 0 13750504
14_july n 1 2 @ #p 1 0 15200493
15 n 1 1 @ 1 1 13747469
1530s n 1 1 @ 1 0 15148787
15_august_1945 n 1 1 @ 1 0 15162882
15_may_organization n 1 2 @ ; 1 0 08039312
15_minutes n 1 2 @ #p 1 1 15228267
16 n 1 1 @ 1 1 13747606
16_pf n 1 1 @ 1 0 06475933
17 n 1 1 @ 1 1 13747725
1728 n 1 1 @ 1 0 13751158
1750s n 1 1 @ 1 0 15149933
1760s n 1 1 @ 1 0 15150304
2_chronicles n 1 2 @ #p 1 0 06435916
2_esdras n 1 2 @ #p 1 0 06460167
2_kings n 1 2 @ #p 1 0 06435198
2_maccabees n 1 2 @ #p 1 0 06460926
2_samuel n 1 2 @ #p 1 0 06434826
2nd_lieutenant n 1 1 @ 1 0 10569011
3 n 1 1 @ 1 1 13744044

Topic archived. No new replies allowed.