Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
Reading .ini files

 
Post new topic   Reply to topic Printable version
 View previous topic  Retard Quetion Post :: Post What does this mean Delta?  View next topic  
Author Message
Dark_Nexus
Newbie


Age:39
Gender:Gender:Female
Joined: Jan 02 2004
Posts: 23
Offline

PostPosted: Sun Feb 29, 2004 12:37 am    Post subject: Reading .ini files Reply to topic Reply with quote

okies, here is the format of my .ini

[Player Name]
CurrentQuestion=1
Status=N/A

Example...

[Dark_Nexus]
CurrentQuestion=1
Status=fired.

here is my code...

Code: Show/Hide
bool botInfo::check_name(char* name0)
{
   GetPrivateProfileString(name0,"CurrentQuestion",0,name,32,path);
   if (name) return true;
   else return false;   
}


path = the path to the .ini file (C:\My Documents....ect)
name = a 32 character buffer (char name[32])
name0 = the name that that the player typed in !read <player name>

I call it in command.cpp when a player types !read <palyer name>
the function gets called like check_name(c->final);

The function simply reads throught the .ini file and checks for that players name. If it can't find it, it should put nothing into the buffer, and then return false, if it does find something, it should put the number following "CurrentQuestion" into the buffer and then return true. But the function always return true, even if i type !read bleh, and bleh does not exist in the .ini file. i really need help icon_sad.gif
_________________
"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
View users profile Send private message Add User to Ignore List Send email AIM Address MSN Messenger
Doggeti
Server Help Squatter


Age:40
Gender:Gender:Male
Joined: Jan 12 2003
Posts: 297
Location: Germany
Offline

PostPosted: Sun Feb 29, 2004 1:16 am    Post subject: Reply to topic Reply with quote

I don't understand why you need two functions. I would put all the code from GetPrivateProfileString into check_name and then delete GetPrivate...

However I think you should also post GetPrivateProfileString.
_________________
Expect the worst but hope for the best.
Back to top
View users profile Send private message Add User to Ignore List Send email AIM Address
Dark_Nexus
Newbie


Age:39
Gender:Gender:Female
Joined: Jan 02 2004
Posts: 23
Offline

PostPosted: Sun Feb 29, 2004 1:21 am    Post subject: Reply to topic Reply with quote

GetPrivateProfileString is a standard library function.
Back to top
View users profile Send private message Add User to Ignore List Send email AIM Address MSN Messenger
Guest



Offline

PostPosted: Sun Feb 29, 2004 1:42 am    Post subject: Reply to topic Reply with quote

Use
Code: Show/Hide
GetPrivateProfileString(name0, "CurrentQuestion", "", name, 32, path);

and then check if the strlen of name is zero or not.

Also, name should be of size 33 if you're going to possibly copy up to 32 chars, because you need to leave room for the terminating null character. You should also check that name0 isn't null if you don't already check it before you call the function (in case the user just types !read)
Back to top
NightHawk
Newbie


Joined: Dec 09 2003
Posts: 20
Location: Sabotage'd
Offline

PostPosted: Sun Feb 29, 2004 1:44 am    Post subject: Reply to topic Reply with quote

name can actually be 32, beacuse that parameter is meant to be the size of the buffer
Back to top
View users profile Send private message Add User to Ignore List
Dark_Nexus
Newbie


Age:39
Gender:Gender:Female
Joined: Jan 02 2004
Posts: 23
Offline

PostPosted: Sun Feb 29, 2004 1:50 am    Post subject: Reply to topic Reply with quote

actually from what i read on msdn, "" will not work because the function insters a null character after the string to eliminate blanks like that, so i think i just have to put 0.

and in command.cpp i already check to see if c->checkParam("") to see if they entered a name icon_smile.gif

okies here is my modified function, but i have a question of efficency now,

Code: Show/Hide
bool botInfo::check_name(char* name0)
{
   GetPrivateProfileString(name0,"CurrentQuestion",0,name,32,path);
   if (sizeof(name)>0) return true;
   else return false;   
}


would if (!strcmp(name,"")) return false, be quicker?


Last edited by Dark_Nexus on Sun Feb 29, 2004 1:54 am, edited 1 time in total
Back to top
View users profile Send private message Add User to Ignore List Send email AIM Address MSN Messenger
Guest



Offline

PostPosted: Sun Feb 29, 2004 1:54 am    Post subject: Reply to topic Reply with quote

"" and strlen method works, where as the 0 method doesn't. i just tried it.
Back to top
Dark_Nexus
Newbie


Age:39
Gender:Gender:Female
Joined: Jan 02 2004
Posts: 23
Offline

PostPosted: Sun Feb 29, 2004 2:00 am    Post subject: Reply to topic Reply with quote

hmmm for somereason sizeof is not working there new_let_it_all_out.gif anyways still a question of efficency, would if (!strcmp(name,"")) or if (STRLEN(name)) be faster?

Last edited by Dark_Nexus on Sun Feb 29, 2004 2:02 am, edited 1 time in total
Back to top
View users profile Send private message Add User to Ignore List Send email AIM Address MSN Messenger
Guest



Offline

PostPosted: Sun Feb 29, 2004 2:00 am    Post subject: Reply to topic Reply with quote

oh you've edited your post and are going to use strlen with 0 - ok that works as well.

you can just use

if (!strlen(name)) return false;
else return true;

or:
return (bool) strlen(name);

but the second one isn't super good style imo
Back to top
Guest



Offline

PostPosted: Sun Feb 29, 2004 2:05 am    Post subject: Reply to topic Reply with quote

if you wanted to get super efficient, if (name[0]) would be the most efficient of all. but in these days of Pentium 4s, it doesnt really matter
Back to top
Dark_Nexus
Newbie


Age:39
Gender:Gender:Female
Joined: Jan 02 2004
Posts: 23
Offline

PostPosted: Sun Feb 29, 2004 2:07 am    Post subject: Reply to topic Reply with quote

bleh i think i was doing something similar to that, but i think if i do
Code: Show/Hide
if (name) return true;
was checking the entire array, instead of just the first character, anways, thanks a lot for your help, i really don't understand how to use GetPrivateProfileString and the like that well, and you guys really helped me out icon_biggrin.gif
Back to top
View users profile Send private message Add User to Ignore List Send email AIM Address MSN Messenger
Guest



Offline

PostPosted: Sun Feb 29, 2004 2:17 am    Post subject: Reply to topic Reply with quote

since you said name was a char name[32], using if (name) wouldn't work. 'name' is the address of the start of the string, and since name isn't dynamically allocated (ie it's memory address will never change), if (name) is always going to be true.
Back to top
Dustpuppy
Server Help Squatter


Age:40
Gender:Gender:Male
Joined: Jan 23 2003
Posts: 215
Location: England
Offline

PostPosted: Mon Mar 01, 2004 8:46 pm    Post subject: Reply to topic Reply with quote

Any of

if (*name)
if (name[0])
if (strlen(name))

should work.
_________________
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Mon Mar 01, 2004 10:59 pm    Post subject: Reply to topic Reply with quote

OMG! If you people are going to use C, understand the language first. Jesus Christ!
_________________
4,691 irradiated haggis!
Back to top
View users profile Send private message Add User to Ignore List
Dr Brain
Flip-flopping like a wind surfer


Age:39
Gender:Gender:Male
Joined: Dec 01 2002
Posts: 3502
Location: Hyperspace
Offline

PostPosted: Mon Mar 01, 2004 11:21 pm    Post subject: Reply to topic Reply with quote

Mr Ekted wrote:
OMG! If you people are going to use C, understand the language first. Jesus Christ!


I don't think that what you said is exactly true. It should be "Don't Post C until you understand the language first.
_________________
Hyperspace Owner

Smong> so long as 99% deaths feel lame it will always be hyperspace to me
Back to top
View users profile Send private message Add User to Ignore List AIM Address Yahoo Messenger MSN Messenger
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Tue Mar 02, 2004 12:08 am    Post subject: Reply to topic Reply with quote

No. I meant don't use it. Every time there's a thread about something to do with code, half the people are just taking guess about how the language works, and some of them are actually trying to make stuff. How about read a book first?
Back to top
View users profile Send private message Add User to Ignore List
50% Packetloss
Server Help Squatter


Age:40
Gender:Gender:Male
Joined: Sep 09 2003
Posts: 561
Location: Santa Clarita, California
Offline

PostPosted: Tue Mar 02, 2004 2:33 am    Post subject: Reply to topic Reply with quote

I didnt read much, just pointing out a small thing that bugs me.

Do NOT do if(blah){return true;} else {return false;} . This is ghey and you need to just make a variable. bool Bob=false; and if the function turns out to be true, make bob=true; and then return bob; at the end of the function. Placing returns in the middle of functions is confusing. A bool is 1 byte large, it will be a lot less hassle to just declare the variable and then return it at the end of the function.
Back to top
View users profile Send private message Add User to Ignore List Send email AIM Address
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Tue Mar 02, 2004 3:05 pm    Post subject: Reply to topic Reply with quote

Agreed. Never return in the middle of a function. It is wrong, and can lead to nasty bugs like resource/memory leaks, unclosed files, etc.

Also, if you want to be picky, int is better than bool. It is much faster under Intel (Windows, Linux) to read/write a full 32-bit value than an 8-bit value. Using bool saves data space if there are thousands of them as public/static data, but on the stack they pretty much have no benefit.
Back to top
View users profile Send private message Add User to Ignore List
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> Bot Questions All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 92 page(s) served in previous 5 minutes.

phpBB Created this page in 0.485220 seconds : 42 queries executed (92.8%): GZIP compression disabled