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
C++ help needed

 
Post new topic   Reply to topic Printable version
 View previous topic  Private freqs Post :: Post BIOS clocking problem...  View next topic  
Author Message
Doggeti
Server Help Squatter


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

PostPosted: Sat Jun 21, 2003 4:39 am   Post maybe stupid    Post subject: C++ help needed Reply to topic Reply with quote

I have following code

Code: Show/Hide
char line[256];
   while(afile.getline(line,256))
   {
      if(!inNotes && &line[0] == "[Notes]")
      {
         inNotes = true;
         sendPublic("[Notes] found");
      }


I know that this reads the file correctly and there is a line with '[Notes]' in the file but it never displays the message. Where is the error?
Back to top
View users profile Send private message Add User to Ignore List Send email AIM Address
Smong
Server Help Squatter


Joined: 1043048991
Posts: 0x91E
Offline

PostPosted: Sat Jun 21, 2003 7:01 am   Post maybe stupid    Post subject: Reply to topic Reply with quote

Have you tried strcmp()?
I think == can only be used with string, not char (maybe cast it to string?)
Back to top
View users profile Send private message Add User to Ignore List Visit posters website MSN Messenger
Doggeti
Server Help Squatter


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

PostPosted: Sat Jun 21, 2003 9:06 am   Post maybe stupid    Post subject: Reply to topic Reply with quote

These str-functions might be very usefull if they weren't so confusing:

Why does this line work:

if(inNotes && strchr(tmp, "["))

and this one cause an error:

a = strchr(tmp, "="); // tmp and a are Strings

icon_question.gif
Back to top
View users profile Send private message Add User to Ignore List Send email AIM Address
Smong
Server Help Squatter


Joined: 1043048991
Posts: 0x91E
Offline

PostPosted: Sat Jun 21, 2003 12:35 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

I find them confusing too like strncmp, what is that!? Also:
char * strchr(const char *_s, int _c);
Back to top
View users profile Send private message Add User to Ignore List Visit posters website MSN Messenger
Mine GO BOOM
Hunch Hunch
What What
Hunch Hunch<br>What What


Age:42
Gender:Gender:Male
Joined: Aug 01 2002
Posts: 3615
Location: Las Vegas
Offline

PostPosted: Sat Jun 21, 2003 1:21 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

You really should be using the string class if your doing C++ and have no idea how a char array works. But i'll attempt to give you a low-down of how things are:

Letters are stored in the ASCII format. That means that the letter 'A' is actually seen as the number 65. So any type that can store the number 65 can store the letter 'A'.

int is the standard size of whatever processor your using uses. Its been 32-bit for a while, but with the new 64-bit machines coming into public use soon, int will be 64-bit. So when a function uses int for a single character, it is because thats the standard size the processor likes. You could just have it be the char type, as both will work.

A char* is a pointer (as noted by the *). It points to whatever you want it to. It is NOT a string. It is NOT a new variable. It points to another one. So it works like the following:

Code: Show/Hide
char str[255];
char *p;

strcpy(str, "Hello world");

p = strchr(str, 'w');
if (p)
    p = 'k';

puts(str);

That will print out Hello korld, because the pointer p is pointing directly to where the 'w' was found from strchr. If you change the p = 'k'; into strcpy(p, "friend");, it will print out Hello friend.

strchr just attempts to find a certain character inside of an array of characters. So in the above example, it will go through each letter in the str till it finds a 'w'. Once it does, it returns a pointer to it. If it doesn't find it (say you were looking for a 'z'), it will return 0, which is the same as NULL or false.

strcmp will compare two chars, byte by byte, with each other. If they are identical in everyway, it will return 0. When it returns -1 or 1, it means they are different. As to how, i'll doubt you'll ever use it.

strcmpi will compare like strcmp, but with one difference. It is case insensitve. So that means it will find Hello to be equal to heLlO.

The most common method of finding if two strings are the same inside an if structure is to do !strcmpi(string1, "Text you want"). So for your above example, it would be better to do it as the following: if(!inNotes && !strcmpi(line, "[Notes]"))
Back to top
View users profile Send private message Add User to Ignore List Send email
Doggeti
Server Help Squatter


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

PostPosted: Sat Jun 21, 2003 2:03 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

Thanks for your help, Mine. Now I understand it a little bit better.
Back to top
View users profile Send private message Add User to Ignore List Send email AIM Address
Smong
Server Help Squatter


Joined: 1043048991
Posts: 0x91E
Offline

PostPosted: Sat Jun 21, 2003 5:33 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

Are strncmp(), strcasecmp() and stricmp() the same as strcmpi()?
Back to top
View users profile Send private message Add User to Ignore List Visit posters website MSN Messenger
Mine GO BOOM
Hunch Hunch
What What
Hunch Hunch<br>What What


Age:42
Gender:Gender:Male
Joined: Aug 01 2002
Posts: 3615
Location: Las Vegas
Offline

PostPosted: Sat Jun 21, 2003 11:35 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

Smong wrote:
Are strncmp(), strcasecmp() and stricmp() the same as strcmpi()?


MSDN is your friend. Enter the function name, hit Search, and it will send back info on it. If they were the same, they wouldn't be named differently, so yes, they are different. Some do casing differently, some can let your shorten the string comparing length, etc.
Back to top
View users profile Send private message Add User to Ignore List Send email
Smong
Server Help Squatter


Joined: 1043048991
Posts: 0x91E
Offline

PostPosted: Sun Jun 22, 2003 3:28 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

Thanks for the tip. strcasecmp() isn't there, but I think it's the same as strcmpi() (I did a bit of testing).
Back to top
View users profile Send private message Add User to Ignore List Visit posters website MSN Messenger
Snidjer
Newbie


Age:41
Gender:Gender:Male
Joined: Jun 22 2003
Posts: 19
Location: Netherlands
Offline

PostPosted: Mon Jun 23, 2003 8:44 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

And for the people using UNIX, man is your friend!

BTW: Unless you want a ton of security problems in your code, always use the strncmp, strnspn, strncpy, etc versions of the functions. (These are ANSI C functions, by the way). These functions require you to specify a length along with the string (read: character pointer or character array). If you don't use these functions, your code is highly susceptible to buffer overflow (and possibly underrun) attacks.

For instance, instead of the strcpy(str, "Hello World") in MGB's example there, you should use strncpy(str, "Hello World", 11) (the terminating null is implied in the ANSI C version).

Kind regards,

Devon H. O'Dell
sitetronics.com
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Helicon
Server Help Squatter


Joined: Dec 03 2002
Posts: 771
Location: GNU Doldrums
Offline

PostPosted: Mon Jun 23, 2003 10:44 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

Quote:
MSDN is your friend.


MSDN is not your friend.
I had to say that.

Get a book. Fight the empire.
_________________
Signatures just seem so quaint.
Back to top
View users profile Send private message Add User to Ignore List
Mine GO BOOM
Hunch Hunch
What What
Hunch Hunch<br>What What


Age:42
Gender:Gender:Male
Joined: Aug 01 2002
Posts: 3615
Location: Las Vegas
Offline

PostPosted: Tue Jun 24, 2003 12:10 am   Post maybe stupid    Post subject: Reply to topic Reply with quote

Nothing wrong with using a free resource if its good, no matter the source. Plus with books you have to flip pages, ugh. PDF all the way there.
Back to top
View users profile Send private message Add User to Ignore List Send email
Helicon
Server Help Squatter


Joined: Dec 03 2002
Posts: 771
Location: GNU Doldrums
Offline

PostPosted: Tue Jun 24, 2003 12:41 am   Post maybe stupid    Post subject: Reply to topic Reply with quote

~steal~ the o'reilly books on pdf...?
Back to top
View users profile Send private message Add User to Ignore List
Snidjer
Newbie


Age:41
Gender:Gender:Male
Joined: Jun 22 2003
Posts: 19
Location: Netherlands
Offline

PostPosted: Tue Jun 24, 2003 2:10 am   Post maybe stupid    Post subject: Reply to topic Reply with quote

In any case, I actually prefer *real books* (gasp) over pdf. There are some things that computers just shouldn't replace, IMHO. That or I just really can't study on a computer icon_wink.gif.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Smong
Server Help Squatter


Joined: 1043048991
Posts: 0x91E
Offline

PostPosted: Tue Jun 24, 2003 3:57 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

Snidjer wrote:
For instance, instead of the strcpy(str, "Hello World") in MGB's example there, you should use strncpy(str, "Hello World", 11)
Kind regards,

Let me guess, this is just as bad as strcpy()?
strncpy(str, "Hello World", strlen("Hello World"));
Back to top
View users profile Send private message Add User to Ignore List Visit posters website MSN Messenger
Snidjer
Newbie


Age:41
Gender:Gender:Male
Joined: Jun 22 2003
Posts: 19
Location: Netherlands
Offline

PostPosted: Tue Jun 24, 2003 4:28 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

No, it's better, and in real life, when you're doing strncpy with variables, you will probably be using strlen() on those variables. Good insight.

Devon
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Doggeti
Server Help Squatter


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

PostPosted: Sun Jul 20, 2003 8:20 am   Post maybe stupid    Post subject: Reply to topic Reply with quote

I need help again.

I have:

Code: Show/Hide
char *time; // time is for example '12:34'

int minutes;
int seconds;


How do I get the minutes and seconds from the string (in this case mins=12 and secs=34) and convert them into integers so that the values are in the both integer variables?
Back to top
View users profile Send private message Add User to Ignore List Send email AIM Address
Smong
Server Help Squatter


Joined: 1043048991
Posts: 0x91E
Offline

PostPosted: Sun Jul 20, 2003 12:28 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

sscanf(time, "%d:%d", &minutes, &seconds);
You can try "%2d" if there are always two digits, fx: "00:01", though I doubt it will make much difference.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website MSN Messenger
Doggeti
Server Help Squatter


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

PostPosted: Sun Jul 20, 2003 4:08 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

Thx! That works fine.
Back to top
View users profile Send private message Add User to Ignore List Send email AIM Address
GameMaster
Novice


Age:37
Gender:Gender:Male
Joined: Aug 06 2003
Posts: 48
Location: Vienna
Offline

PostPosted: Fri Aug 15, 2003 6:04 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

Could someone tell me what diffrences are between C++ and Java????
_________________
Me is me...
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Fri Aug 15, 2003 6:35 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

Uhhhh.
C++ is a text-oriented language, and is widely used for almost everything. Complex.

Java is graphic/object-oriented language, and is widely used only on the internet. It has some other uses, but mostly for executables, C++ is the way to go. Java's a heck of a lot similar too. (I can understand it icon_razz.gif)

Please anyone more experienced correct me on any points.
_________________
This help is informational only. No representation is made or warranty given as to its content. User assumes all risk of use. Cyan~Fire assumes no responsibility for any loss or delay resulting from such use.
Wise men STILL seek Him.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
GameMaster
Novice


Age:37
Gender:Gender:Male
Joined: Aug 06 2003
Posts: 48
Location: Vienna
Offline

PostPosted: Sat Aug 16, 2003 4:16 am   Post maybe stupid    Post subject: Reply to topic Reply with quote

I looked at some of the code and it looks like it is a mix of java and php.
can it be?
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Sat Aug 16, 2003 12:29 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

Lol no way. C++ is based on C which has been around for ages.

Almost all programming languages look the same, if you think about it. They just have very different functions. php is nothing like C++ since it handles web pages, and C++ does kinda behind-the-scenes stuff. And I already said how Java is different.

If you want to get into programming, I suggest starting with Visual Basic, and working your way up to C++.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
MadBoy
Newbie


Gender:Gender:Male
Joined: Aug 10 2003
Posts: 14
Location: 2 houses far from GameMaster
Offline

PostPosted: Sat Aug 16, 2003 6:05 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

ok nice to know... ill try
Back to top
View users profile Send private message Add User to Ignore List
GameMaster
Novice


Age:37
Gender:Gender:Male
Joined: Aug 06 2003
Posts: 48
Location: Vienna
Offline

PostPosted: Sat Aug 16, 2003 6:06 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

php handles php-pags
php its if($s==$b){echo "****";}else{echo $b;}

java... (we learned it @ school) ...is useless (there was no useful programm we have done).
in java its if(s==b){system.out.print(ln)("****");}else{system.out.print(ln)( b);}

They look nearly same... no matter what they are for!

... visual basic????
no thx that dosnt even look same!
I think VB is just 4 MS office access... never saw it snywhere else.

Is is really to hard to learn C++ from mixing php & java????

... im posting shit i know.... lol
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> Trash Talk 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 cannot 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: 41 page(s) served in previous 5 minutes.

phpBB Created this page in 0.890244 seconds : 47 queries executed (84.4%): GZIP compression disabled