Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Poll

What programming topic would you want the next challenge to be about?  (It might be a good opportunity to focus on a subject you're not familiar with or to reinforce knowledge on one that you already know)

Control Flow
- 2 (2.2%)
Arrays, Strings, Pointers, and References
- 8 (9%)
Functions
- 4 (4.5%)
Basic object-oriented programming
- 30 (33.7%)
A bit more advanced OOP (Composition, Operator overloading, Inheritance, Virtual Functions)
- 18 (20.2%)
Templates
- 8 (9%)
Other (Explain)
- 4 (4.5%)
Working with files?  (Streams)
- 15 (16.9%)

Total Members Voted: 89


Pages: 1 ... 67 68 [69] 70 71 ... 78

Author Topic: Programming Challenges & Resources (#bay12prog) Initiative  (Read 95705 times)

Blank Expression

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #1020 on: March 06, 2011, 05:16:40 pm »

Dangerous assumptions there. sizeof(int) on your computer does not have to be the same as the computer that wrote the file. When dealing with file headers, always know the byte count of each data element and read that amount explicitly.

Edit: Would help to know the (hex) contents of the file.
Or just use the defined typedefs that say exactly how big something is. I want to punch a kitten whenever somebody uses "int". Every modern compiler includes stdint.h/cstdint. If you're going to be misusing C++, at least misuse it with the right tools.
Logged

Shades

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #1021 on: March 07, 2011, 03:33:10 am »

Or just use the defined typedefs that say exactly how big something is. I want to punch a kitten whenever somebody uses "int". Every modern compiler includes stdint.h/cstdint.

Just to expand on that all the implementations of the standards have to support int8_t, int16_t, int32_t, uint8_t, uint16_t and uint32_t which are signed and unsigned 8, 16 and 32 bit values.

There is also a lot of other constants that are useful but those are the ones you'll use most commonly.
Logged
Its like playing god with sentient legos. - They Got Leader
[Dwarf Fortress] plays like a dizzyingly complex hybrid of Dungeon Keeper and The Sims, if all your little people were manic-depressive alcoholics. - tv tropes
You don't use science to show that you're right, you use science to become right. - xkcd

olemars

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #1022 on: March 07, 2011, 03:54:58 am »

Only full implementations of C99. Visual Studio hasn't had a stdint.h in any versions prior to VS2010. Instead there are alternatives like __int8/16/32 and so on.
Logged

Shades

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #1023 on: March 07, 2011, 05:04:47 am »

Only full implementations of C99. Visual Studio hasn't had a stdint.h in any versions prior to VS2010. Instead there are alternatives like __int8/16/32 and so on.

Unless they use boost which has an implementation of it, and why wouldn't they be using boost if they are working in c++?

Alternatively on visual studio 2005 or later you can use the files at http://code.google.com/p/msinttypes/ which is an implementation for visual studio. Of course if your using the free version of VS you may as well upgrade so you can abuse the cool functionality in the 2010 compiler.
Logged
Its like playing god with sentient legos. - They Got Leader
[Dwarf Fortress] plays like a dizzyingly complex hybrid of Dungeon Keeper and The Sims, if all your little people were manic-depressive alcoholics. - tv tropes
You don't use science to show that you're right, you use science to become right. - xkcd

ILikePie

  • Bay Watcher
  • Call me Ron
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #1024 on: March 07, 2011, 07:44:41 am »

Spoiler (click to show/hide)
Never mind, I forgot puts stops printing when it reaches a null character.
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #1025 on: March 07, 2011, 07:49:38 am »

Never mind, I forgot puts stops printing when it reaches a null character.
Hahaha, don't you love those "errors", where you only think something is wrong even if there isn't :D
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

qwertyuiopas

  • Bay Watcher
  • Photoshop is for elves who cannot use MSPaint.
    • View Profile
    • uristqwerty.ca, my current (barren) site.
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #1026 on: March 07, 2011, 02:47:51 pm »

Doesn't windows.h (or some similar header) define a struct that corresponds to the header of a bitmap? I think they are BITMAPFILEHEADER and BITMAPINFOHEADER. Instead of reading by offset, then, you could directly read in the correct struct, then use the value that it contains. Bonus: There are more than one of those structs, so using one would make it easier to use others in turn.
Logged
Eh?
Eh!

Blank Expression

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #1027 on: March 07, 2011, 03:00:33 pm »

Only full implementations of C99. Visual Studio hasn't had a stdint.h in any versions prior to VS2010. Instead there are alternatives like __int8/16/32 and so on.
Good point, I forgot about that. As Shades noted, though, there are replacements.

(But, really, you can use the VS2010 compiler--which is a free download--with versions of VS as far back as VS2005, there's not much of a reason not to.)
Logged

ILikePie

  • Bay Watcher
  • Call me Ron
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #1028 on: March 07, 2011, 04:37:09 pm »

Doesn't windows.h (or some similar header) define a struct that corresponds to the header of a bitmap? I think they are BITMAPFILEHEADER and BITMAPINFOHEADER. Instead of reading by offset, then, you could directly read in the correct struct, then use the value that it contains. Bonus: There are more than one of those structs, so using one would make it easier to use others in turn.
Microsoft has it on their site, and Wikipedia has nice documentation of bitmaps too.
Logged

SolarShado

  • Bay Watcher
  • Psi-Blade => Your Back
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #1029 on: March 07, 2011, 08:47:11 pm »

Of course if your using the free version of VS you may as well upgrade so you can abuse the cool functionality in the 2010 compiler.

* SolarShado is interested
such as?
Logged
Avid (rabid?) Linux user. Preferred flavor: Arch

olemars

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #1030 on: March 08, 2011, 03:40:22 am »

VS2010 has some C++0x support.
Logged

TolyK

  • Bay Watcher
  • Nowan Ilfideme
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #1031 on: March 08, 2011, 03:41:02 am »

C++0x is incl
VS2010 has some C++0x support.
Ninja'd.
Logged
My Mafia Stats
just do whatevery tolyK and blame it as a bastard mod
Shakerag: Who are you personally suspicious of?
At this point?  TolyK.

malimbar04

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #1032 on: March 11, 2011, 10:04:07 am »

Attempted to make a basic calculator, but for some reason it's giving me really strange answers. 23 * 45 gives an answer of 4.88005e-270 for example. Please help me debug... because I have no idea what it's doing wrong.

Spoiler (click to show/hide)
Logged
No! No! I will not massacre my children. Instead, I'll make them corpulent on crappy mass-produced quarry bush biscuits and questionably grown mushroom alcohol, and then send them into the military when they turn 12...

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #1033 on: March 11, 2011, 10:31:04 am »

Your switch. It is wrong.

you'll want
case '+':

instead of
case 1: '+';

Right now it skips those, and prints solution = 0, except that doubles and floats are often almost zero, so that's what you see.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

malimbar04

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #1034 on: March 11, 2011, 11:02:03 am »

ah, that makes more sense, thanks.

It also revealed an error that happened when I was changing the name of variables, I was attaching the solution to the final sentence, displaying something like 115 + 6 = 11. the 115 is just 11 attached to the real sentence of 5+6=11.

Sweetness.
Logged
No! No! I will not massacre my children. Instead, I'll make them corpulent on crappy mass-produced quarry bush biscuits and questionably grown mushroom alcohol, and then send them into the military when they turn 12...
Pages: 1 ... 67 68 [69] 70 71 ... 78