Author |
Message |
Doggeti Server Help Squatter

Age:40 Gender: Joined: Jan 12 2003 Posts: 297 Location: Germany Offline
|
|
Back to top |
|
 |
Smong Server Help Squatter

Joined: 1043048991 Posts: 0x91E Offline
|
Posted: Sat Jun 21, 2003 7:01 am Post maybe stupid Post subject: |
 |
|
|
|
Have you tried strcmp()?
I think == can only be used with string, not char (maybe cast it to string?) |
|
Back to top |
|
 |
Doggeti Server Help Squatter

Age:40 Gender: Joined: Jan 12 2003 Posts: 297 Location: Germany Offline
|
Posted: Sat Jun 21, 2003 9:06 am Post maybe stupid Post subject: |
 |
|
|
|
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
 |
|
Back to top |
|
 |
Smong Server Help Squatter

Joined: 1043048991 Posts: 0x91E Offline
|
Posted: Sat Jun 21, 2003 12:35 pm Post maybe stupid Post subject: |
 |
|
|
|
I find them confusing too like strncmp, what is that!? Also:
char * strchr(const char *_s, int _c); |
|
Back to top |
|
 |
Mine GO BOOM Hunch Hunch What What

Age:42 Gender: Joined: Aug 01 2002 Posts: 3615 Location: Las Vegas Offline
|
Posted: Sat Jun 21, 2003 1:21 pm Post maybe stupid Post subject: |
 |
|
|
|
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:
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 |
|
 |
Doggeti Server Help Squatter

Age:40 Gender: Joined: Jan 12 2003 Posts: 297 Location: Germany Offline
|
Posted: Sat Jun 21, 2003 2:03 pm Post maybe stupid Post subject: |
 |
|
|
|
Thanks for your help, Mine. Now I understand it a little bit better. |
|
Back to top |
|
 |
Smong Server Help Squatter

Joined: 1043048991 Posts: 0x91E Offline
|
Posted: Sat Jun 21, 2003 5:33 pm Post maybe stupid Post subject: |
 |
|
|
|
Are strncmp(), strcasecmp() and stricmp() the same as strcmpi()? |
|
Back to top |
|
 |
Mine GO BOOM Hunch Hunch What What

Age:42 Gender: Joined: Aug 01 2002 Posts: 3615 Location: Las Vegas Offline
|
Posted: Sat Jun 21, 2003 11:35 pm Post maybe stupid Post subject: |
 |
|
|
|
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 |
|
 |
Smong Server Help Squatter

Joined: 1043048991 Posts: 0x91E Offline
|
Posted: Sun Jun 22, 2003 3:28 pm Post maybe stupid Post subject: |
 |
|
|
|
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 |
|
 |
Snidjer Newbie
Age:41 Gender: Joined: Jun 22 2003 Posts: 19 Location: Netherlands Offline
|
Posted: Mon Jun 23, 2003 8:44 pm Post maybe stupid Post subject: |
 |
|
|
|
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 |
|
 |
Helicon Server Help Squatter
Joined: Dec 03 2002 Posts: 771 Location: GNU Doldrums Offline
|
Posted: Mon Jun 23, 2003 10:44 pm Post maybe stupid Post subject: |
 |
|
|
|
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 |
|
 |
Mine GO BOOM Hunch Hunch What What

Age:42 Gender: Joined: Aug 01 2002 Posts: 3615 Location: Las Vegas Offline
|
Posted: Tue Jun 24, 2003 12:10 am Post maybe stupid Post subject: |
 |
|
|
|
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 |
|
 |
Helicon Server Help Squatter
Joined: Dec 03 2002 Posts: 771 Location: GNU Doldrums Offline
|
Posted: Tue Jun 24, 2003 12:41 am Post maybe stupid Post subject: |
 |
|
|
|
~steal~ the o'reilly books on pdf...? |
|
Back to top |
|
 |
Snidjer Newbie
Age:41 Gender: Joined: Jun 22 2003 Posts: 19 Location: Netherlands Offline
|
Posted: Tue Jun 24, 2003 2:10 am Post maybe stupid Post subject: |
 |
|
|
|
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 . |
|
Back to top |
|
 |
Smong Server Help Squatter

Joined: 1043048991 Posts: 0x91E Offline
|
Posted: Tue Jun 24, 2003 3:57 pm Post maybe stupid Post subject: |
 |
|
|
|
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 |
|
 |
Snidjer Newbie
Age:41 Gender: Joined: Jun 22 2003 Posts: 19 Location: Netherlands Offline
|
Posted: Tue Jun 24, 2003 4:28 pm Post maybe stupid Post subject: |
 |
|
|
|
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 |
|
 |
Doggeti Server Help Squatter

Age:40 Gender: Joined: Jan 12 2003 Posts: 297 Location: Germany Offline
|
|
Back to top |
|
 |
Smong Server Help Squatter

Joined: 1043048991 Posts: 0x91E Offline
|
Posted: Sun Jul 20, 2003 12:28 pm Post maybe stupid Post subject: |
 |
|
|
|
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 |
|
 |
Doggeti Server Help Squatter

Age:40 Gender: Joined: Jan 12 2003 Posts: 297 Location: Germany Offline
|
Posted: Sun Jul 20, 2003 4:08 pm Post maybe stupid Post subject: |
 |
|
|
|
Thx! That works fine. |
|
Back to top |
|
 |
GameMaster Novice

Age:37 Gender: Joined: Aug 06 2003 Posts: 48 Location: Vienna Offline
|
Posted: Fri Aug 15, 2003 6:04 pm Post maybe stupid Post subject: |
 |
|
|
|
Could someone tell me what diffrences are between C++ and Java???? _________________ Me is me... |
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Fri Aug 15, 2003 6:35 pm Post maybe stupid Post subject: |
 |
|
|
|
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 )
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 |
|
 |
GameMaster Novice

Age:37 Gender: Joined: Aug 06 2003 Posts: 48 Location: Vienna Offline
|
Posted: Sat Aug 16, 2003 4:16 am Post maybe stupid Post subject: |
 |
|
|
|
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 |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Sat Aug 16, 2003 12:29 pm Post maybe stupid Post subject: |
 |
|
|
|
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 |
|
 |
MadBoy Newbie
Gender: Joined: Aug 10 2003 Posts: 14 Location: 2 houses far from GameMaster Offline
|
Posted: Sat Aug 16, 2003 6:05 pm Post maybe stupid Post subject: |
 |
|
|
|
ok nice to know... ill try |
|
Back to top |
|
 |
GameMaster Novice

Age:37 Gender: Joined: Aug 06 2003 Posts: 48 Location: Vienna Offline
|
Posted: Sat Aug 16, 2003 6:06 pm Post maybe stupid Post subject: |
 |
|
|
|
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 |
|
 |
|