| Author | Message | 
	
		| Dark_Nexus Newbie
 
  
 Age:40
 Gender:
  Joined: Jan 02 2004
 Posts: 23
 Offline
 
 | 
			
			  | 
				
					|  Posted: Wed Apr 07, 2004 12:41 am     Post subject: Buffer Issues :/ |  |   |  |  
				| 
 |  
				| I am using a windows function to access reg keys and .ini files, here is the function with its syntax: 
 GetPrivateProfileSection(section name,buffer name,size of buffer,path to file)
 
 so lets say i have an .ini file with one section and use that function to retrieve the data from it:
 
 [Operators]
 Dark_Nexus=3
 blehbleh=4
 bleep=2
 
 the way it returns the section is, each data key gets put into the buffer as a string, it is followed by a NULL terminating character, and the last string of the buffer has two NULL terminating characters.  So it looks like this in the buffer:
 
 Dark_Nexus=3 \n blehbleh=4 \n bleep=2 \n\n
 
 So now lets say i want to assign a variable to the buffer, as in:
 
 String msg = buffer;
 
 now String msg will only equal the first string, as in Dark_Nexus=3, because it encounters the first NULL terminating character and thinks it is a string.
 
 So i need a way to sort through the buffer, and place the data i need into a String variable.
 
 here is what i have tried (and does not work):
 
 
 
 
 	| msg = "Operators: ";
GetPrivateProfileSection("Operators",buffer,250,path);
 String opstr = buffer;
 GetPrivateProfileString("Operators","ASOCount",0,question_num,3,path);
 for (int i = 1;i <= atoi(question_num);i++)
 {
 msg += opstr.split('\n');
 msg += ", ";
 }
 sendPrivate(p,msg);
 | 
 
 so lets say i have 3 moderators, it will look like this in game:
 
 Bot> Operators: Dark_Nexus=3, Dark_Nexus=3, Dark_Nexus=3
 
 
  helppppp _________________
 "In fact, about the only reasonable holiday is 4th of July (US). We celebrate something that actually happened by blowing shit up."
 -Mr Ekted
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Mr Ekted Movie Geek
 
  
 Gender:
  Joined: Feb 09 2004
 Posts: 1379
 Offline
 
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Mine GO BOOM Hunch Hunch
 What What
 
  
 
 Age:42
 Gender:
  Joined: Aug 01 2002
 Posts: 3615
 Location: Las Vegas
 Offline
 
 | 
			
			  | 
				
					|  Posted: Wed Apr 07, 2004 10:28 am     Post subject: |  |   |  |  
				| 
 |  
				|  	  | Mr Ekted wrote: |  	  | This shows C's strength: the ability to handle memory in an arbitrary format. | 
 Would you come up with a source to show in anyway how C++ is a subset of C?
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Mr Ekted Movie Geek
 
  
 Gender:
  Joined: Feb 09 2004
 Posts: 1379
 Offline
 
 | 
			
			  | 
				
					|  Posted: Wed Apr 07, 2004 11:41 am     Post subject: |  |   |  |  
				| 
 |  
				| C++ is a superset of C. I'm not sure what you are asking. |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| D1st0rt Miss Directed Wannabe
 
  
 Age:37
 Gender:
  Joined: Aug 31 2003
 Posts: 2247
 Location: Blacksburg, VA
 Offline
 
 | 
			
			  | 
				
					|  Posted: Wed Apr 07, 2004 11:50 am     Post subject: |  |   |  |  
				| 
 |  
				| Heres a solution, thanks to Dustpuppy: 
 It's golden
  _________________
 
   
   
 
 
 From the EXPLBOT source
 
  iniaccess.zip - 1.56 KB File downloaded or viewed 15 time(s)
 
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| 50% Packetloss Server Help Squatter
 
  
 Age:40
 Gender:
  Joined: Sep 09 2003
 Posts: 561
 Location: Santa Clarita, California
 Offline
 
 | 
			
			  | 
				
					|  Posted: Wed Apr 07, 2004 12:36 pm     Post subject: |  |   |  |  
				| 
 |  
				| char *INIAccess::GetString(char *section, char *key, char *strdefault) 
 if you run this function, make sure you delete [] what it returns, so that you dont get a memory leak
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Mr Ekted Movie Geek
 
  
 Gender:
  Joined: Feb 09 2004
 Posts: 1379
 Offline
 
 | 
			
			  | 
				
					|  Posted: Wed Apr 07, 2004 1:22 pm     Post subject: |  |   |  |  
				| 
 |  
				| This is one of my main dislikes of C++ (if you go overboard). It makes the coding at the top level look all nice and simple, when in fact, there's 10x more going on under the hood. More code executing (slower + larger), and unnecessary memory allocations/frees. IMO, C++ is best used to encapsulate large functional blocks. Of course, you can do this in C just as well. |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| 50% Packetloss Server Help Squatter
 
  
 Age:40
 Gender:
  Joined: Sep 09 2003
 Posts: 561
 Location: Santa Clarita, California
 Offline
 
 | 
			
			  | 
				
					|  Posted: Wed Apr 07, 2004 1:50 pm     Post subject: Re: Buffer Issues :/ |  |   |  |  
				| 
 |  
				|  	  | Dark_Nexus wrote: |  	  | the way it returns the section is, each data key gets put into the buffer as a string, it is followed by a NULL terminating character, and the last string of the buffer has two NULL terminating characters.  So it looks like this in the buffer:
 
 Dark_Nexus=3 \n blehbleh=4 \n bleep=2 \n\n
 
 | 
 
 rofl, a null looks like \0
 the \n is a newline character.
 
 I dont think that function will work anyway.
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Dustpuppy Server Help Squatter
 
  
 Age:40
 Gender:
  Joined: Jan 23 2003
 Posts: 215
 Location: England
 Offline
 
 | 
			
			  | 
				
					|  Posted: Wed Apr 07, 2004 3:47 pm     Post subject: |  |   |  |  
				| 
 |  
				| That class doesn't provide for reading an entire section, which is what Dark Nexus wanted. To be honest, INIs aren't meant for this sort of data and you would be better off reading from a standard text file, one operator to a line.
 
 If you really wanted to keep it in an ini, perhaps you could use:
 
 [Operators]
 Sysop=Foo:Bar
 Smod=Blah:bleh
 
 etc
 
 If you wanted to keep your current format, I think Ekted's code would be best. But if you wanted to use a MERV String, you could try using a strncpy:
 I believe GetPrivateProfileSection returns the length of the string it copied into buffer, so you could store the length it returned, then strncpy into your String.msg, and use split on the newlines.
 
 I can't remember if the String object lets you access the msg property though.
 _________________
 
   |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Cyan~Fire I'll count you!
 
  
 
 Age:37
 Gender:
  Joined: Jul 14 2003
 Posts: 4608
 Location: A Dream
 Offline
 
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Dark_Nexus Newbie
 
  
 Age:40
 Gender:
  Joined: Jan 02 2004
 Posts: 23
 Offline
 
 | 
			
			  | 
				
					|  Posted: Wed Apr 07, 2004 8:37 pm     Post subject: |  |   |  |  
				| 
 |  
				| GetPrivateProfileSection is a standard windows function...i would hope it was microsoft tested and approved   |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Mr Ekted Movie Geek
 
  
 Gender:
  Joined: Feb 09 2004
 Posts: 1379
 Offline
 
 | 
			
			  | 
				
					|  Posted: Wed Apr 07, 2004 10:39 pm     Post subject: |  |   |  |  
				| 
 |  
				|  	  | Dark_Nexus wrote: |  	  | GetPrivateProfileSection is a standard windows function...i would hope it was microsoft tested and approved  | 
 
 Agreed. Don't roll your own with INI files.
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Cyan~Fire I'll count you!
 
  
 
 Age:37
 Gender:
  Joined: Jul 14 2003
 Posts: 4608
 Location: A Dream
 Offline
 
 | 
			
			  | 
				
					|  Posted: Wed Apr 07, 2004 10:52 pm     Post subject: |  |   |  |  
				| 
 |  
				| Except for the fact that file file you're writing is not really an INI. |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Dustpuppy Server Help Squatter
 
  
 Age:40
 Gender:
  Joined: Jan 23 2003
 Posts: 215
 Location: England
 Offline
 
 | 
			
			  | 
				
					|  Posted: Thu Apr 08, 2004 7:56 pm     Post subject: |  |   |  |  
				| 
 |  
				| It is an INI but it shouldn't be. I already went over this... |  | 
	
		| Back to top |  | 
	
		|  | 
	
		|  |