C++ makes things longer

Computer builds, hardware and software discussion or troubleshooting, including peripherals. Essentially a general place to talk about desktop computers.
Locked
User avatar
Red Squirrel
Posts: 29209
Joined: Wed Dec 18, 2002 12:14 am
Location: Northern Ontario
Contact:

C++ makes things longer

Post by Red Squirrel »

I never considered this, but this is kind of funny:

Code: Select all

  char listenmessage[45];
  char tmp[15];
  memset(listenmessage,0,70);
  memset(tmp,0,15);
  strcpy(listenmessage,"Listening on port ");
  sprintf(tmp,%d,listenport);
  strcat(listenmessage,tmp);
callfunction(listenmessage);
[code]

In php:

[code]
<?php callfunction("Listening on port ".$listenport);?>
[code]


:lol: 

[color=#888888][size=85]Archived topic from Iceteks,  old topic ID:3508, old post ID:28389[/size][/color]
Honk if you love Jesus, text if you want to meet Him!
Pyr-O-Rgasm
Posts: 954
Joined: Mon Jan 17, 2005 5:16 pm

C++ makes things longer

Post by Pyr-O-Rgasm »

Wow. Isn't that a :censored:! Maybe not as big of one as my mom, but a :censored: none-the-less.

Archived topic from Iceteks, old topic ID:3508, old post ID:28390
Cold Drink
Posts: 96
Joined: Fri Jul 16, 2004 1:04 pm

C++ makes things longer

Post by Cold Drink »

The really funny thing is your PHP code is too long :)

Code: Select all

<?php=callfunction("Listening on port $listenport");?[code]
or if short_open_tags is on
[code]<?=callfunction("Listening on port $listenport");?[code]
 

[color=#888888][size=85]Archived topic from Iceteks,  old topic ID:3508, old post ID:28391[/size][/color]
User avatar
Red Squirrel
Posts: 29209
Joined: Wed Dec 18, 2002 12:14 am
Location: Northern Ontario
Contact:

C++ makes things longer

Post by Red Squirrel »

Actually I heard that's not a good way of doing it. Not sure why though.

I just wish C++ had a nice syntax like php. :P

Strings do make things easier though, but lot of functions still use chars.

Hmm now that I think of it, I can probably use strings and dump it right in a function by going stringname.c_str(). Just thought of that now.

With strings that would cut the memset part, and make adding easier as I can just go string1 + string2.

*redesigns that part*

Archived topic from Iceteks, old topic ID:3508, old post ID:28392
Honk if you love Jesus, text if you want to meet Him!
User avatar
Red Squirrel
Posts: 29209
Joined: Wed Dec 18, 2002 12:14 am
Location: Northern Ontario
Contact:

C++ makes things longer

Post by Red Squirrel »

Pyr-O-Rgasm wrote: Wow. Isn't that a :censored:! Maybe not as big of one as my mom, but a :censored: none-the-less.
LOL

I hope your mom does not happen to come and see your posts. :P Clear the history! :D

Archived topic from Iceteks, old topic ID:3508, old post ID:28393
Honk if you love Jesus, text if you want to meet Him!
User avatar
Red Squirrel
Posts: 29209
Joined: Wed Dec 18, 2002 12:14 am
Location: Northern Ontario
Contact:

C++ makes things longer

Post by Red Squirrel »

Wow using strings helped...

Code: Select all

NSS_logger("Listening on port " + Int2string(listenport),0);
[code]


The int2string() function is in my custom header file and contains this:

[code]
string Int2string(int number)
{
char tmp[30];
sprintf(tmp,"%d",number);

return tmp;
}
[code]


Much, much easier.  But does not beat php though. :P 

[color=#888888][size=85]Archived topic from Iceteks,  old topic ID:3508, old post ID:28394[/size][/color]
Honk if you love Jesus, text if you want to meet Him!
Pyr-O-Rgasm
Posts: 954
Joined: Mon Jan 17, 2005 5:16 pm

C++ makes things longer

Post by Pyr-O-Rgasm »

Red Squirrel wrote:
Pyr-O-Rgasm wrote: Wow. Isn't that a :censored:! Maybe not as big of one as my mom, but a :censored: none-the-less.
LOL

I hope your mom does not happen to come and see your posts. :P Clear the history! :D
Three people living in this house, three computers. One computer per person. If she were to touch my computer I'd be pissed. Besides, I don't have AOL on my PC and she doesn't know how to work the internet without AOL.

Archived topic from Iceteks, old topic ID:3508, old post ID:28395
User avatar
Red Squirrel
Posts: 29209
Joined: Wed Dec 18, 2002 12:14 am
Location: Northern Ontario
Contact:

C++ makes things longer

Post by Red Squirrel »

LOL that's funny. Just make sure you're on a switch and not a hub... but if she can't figure out a real browser I doubt she can figure out a packet sniffer anyway. :lol:

Archived topic from Iceteks, old topic ID:3508, old post ID:28396
Honk if you love Jesus, text if you want to meet Him!
wtd
Posts: 157
Joined: Sat Sep 25, 2004 7:21 pm

C++ makes things longer

Post by wtd »

Never use char arrays as strings in C++. If you really need a character array for some other function, use the c_str() member function.

Archived topic from Iceteks, old topic ID:3508, old post ID:28451
User avatar
Red Squirrel
Posts: 29209
Joined: Wed Dec 18, 2002 12:14 am
Location: Northern Ontario
Contact:

C++ makes things longer

Post by Red Squirrel »

Yeah I try to do that as much as possible. I'm glad I got to learning strings, since they make stuff a bit more like php, such as unlimited string lenghts, and no need to declare and reserve memory, etc.

Archived topic from Iceteks, old topic ID:3508, old post ID:28453
Honk if you love Jesus, text if you want to meet Him!
Locked