CoolGamer48 65 Posting Pro in Training

Oh, you're right.

But actually, I dropped the system of using different members for red, green, blue, and alpha. I'm just using a single hex value as a member to save space.

Edit:
Just wondering, would this be any faster:

unsigned int red = (hex << 8) >> 16;
//or is it:
unsigned int red = (hex << 8) >> 24;
VernonDozier commented: Interesting question. +6
CoolGamer48 65 Posting Pro in Training

Don't use spaces between in the code tags for them to work.

That code is swapping the variables word and word[j]. Temp is needed to do the switch (at least the way it's being done here).

Say you have a bucket A full of orange juice and bucket B full of water. To swap them you'd need a third bucket named temp. First, pore the oj in A into temp. Now A is empty (well, not in the program, but just roll with it), and temp has oj. Then, pore the water from B into A. A has water, B is empty, and temp has the oj. Now, dump the oj from temp into B. There. You've swapped them.

Hope this helped a bit.

CoolGamer48 65 Posting Pro in Training

the string::c_str() method converts the contents of an std::string to const char*. For example:

string str1 = "Hello";
const char* str2 = "Hello";
str1.c_str();//would return a value equivalent to str2

further information here

You'd be better off using string streams though. there isn't a need to convert an std::string into an old C-string (const char*). string streams can handle std::strings and C-strings.

Salem commented: Say yes to string streams, no to atoi +20
CoolGamer48 65 Posting Pro in Training

*sigh*

Okay, you want to know where to start. I've never written an AVI loader - but here are a couple of places to start (and I don't think where you start is going to be language specific).

  • Learn how to make a GUI. I gave you a link for a starting tutorial for the windows API. If you've got access to MFC (which I believe is just a wrapper for the API), then use that. Don't want to use the API? How about DirectX? A bit more complicated but you can make the GUI look like whatever you like. Rather use something a little more open source? OpenGL (same scenario as DirectX). You're not on Windows? What OS are you on? OpenGL still applies, but there may be other options. So, go out to Google, and try to make a GUI. If you run into specific problems, come back and tell us. Some examples: Can you guys show me the basic structure of a Windows application using the Windows API? better yet: I wrote this GUI (post the code) and it won't compile. Here are the errors: <errors here>. How can I fix it?
  • Learn to interface with SQL. Just Google it. You should get some APIs and tutorials for whatever language you want. Those should help you. If you then have specific questions about that, post them.
  • Learn to load an AVI file. This is a bit more difficult. I gave you link in my previous …
CoolGamer48 65 Posting Pro in Training

I'm writing a program for a contest (it's a demo, not the actual thing - so I'm not cheating by asking for help - and my question isn't directly related to the algorithm they want anyway). To submit a program, you send them the .cpp file, and they execute it on their server (automatically) for a number of test trials (around 10), and show you the results. This problem has 11 trials. For the first five trials, the program runs fine. However, the sixth run of the program fails, and it throws std::bad_alloc (I'm guessing its caused by vector::push_back - the only other things I'm using from std are file streams and strings). Then, trial 7 works fine. Trials 8 and 9 failed, same reason. Trial 10's runtime was too long (it was stopped at around 1.5 secs, shouldn't go over 1 second), and trial 11 had the bad_alloc again.

I wanted to see exactly where the bad_alloc was occurring, so I copied the test input data for trial 6 into the test input file on my machine, and ran the program. I didn't get bad_alloc, but the program didn't end (for the time I ran it, maybe 10 seconds - I'm going to try leaving it for longer while outputting debug info).

Anyway - this is my assumption of what's going on, tell me if I'm right:
On the virtual machine on the competition's servers, the program is only given the amount of memory that they …

Salem commented: Yes, your analysis seems correct. +20
CoolGamer48 65 Posting Pro in Training

I tried everything and none of them worked on my friend's computers. :( Most commonly they said to download Visual C++ 2008 Redistributable package, but I'm using Visual C++ 2008 Express. Any suggestions?

It doesn't matter if you're using Express. I had to do the same thing.

CoolGamer48 65 Posting Pro in Training

A friend of mine recently asked me how one would convert a .bmp font to a .ttf. I said I was unsure, but it got me thinking to how I would code a program to do that. How would someone who wants to create a .bmp to .ttf converter go about it? Is there some sort of documentation somewhere explaining how the .ttf file format works? And in addition to that, what about other file formats? Where do the people who code programs that create .jpegs or play .mp3s learn about how to properly read/write from those file formats? Is the information publicly available by somewhere?

VernonDozier commented: Excellent question, and one I'd like to know the answer of too. I'll be watching this thread! +5
CoolGamer48 65 Posting Pro in Training

It isn't bogus crap. Learn to understand it and you'll begin to be able to solve problems on your own, though its understandable that at first you'll have no idea what it means.

The compilers complaining that the function PlaySound is declared somewhere, but it has no implementation. I'm actually not sure why it said it twice. The implementation would either be in the form of a .cpp file, or, in this case, a .lib file.

To fix this you need to link to the .lib winmm.lib. A simple way to do this is to add

#pragma comment(lib,"winmm.lib")

in one of your source files.

Wiki_Tiki commented: Helped well with 2 fatal compiler errors +1
CoolGamer48 65 Posting Pro in Training

Trying using surfaces instead of textures. link I believe that surfaces are supposed to be used for backgrounds, like the one you're using, and textures should be used for sprites, which often do have widths and heights that are powers of two.

Nick Evan commented: Good advice! +8
CoolGamer48 65 Posting Pro in Training

If you'd like to link to a lib through the compiler's interface rather than using #pragma, right-click on your project's name in the panel to the left, go down to properties, expand linker, go to input, and put the libraries names in the additional dependencies field, separated by spaces.

guy40az commented: thanks again !!! +2
CoolGamer48 65 Posting Pro in Training

Depending on how much of a beginner you are, you may want to stick with console apps for a while and get a handle around pointers, classes, inheritance, and polymorphism to some degree. But, you don't necessarily have to.

If you're on Windows, this is a very good place to begin. As Duoas said, there's a way to do a background with just the Windows API, though if you want to go into more graphical applications, you can try to delve on in to Direct3D.

Alex Edwards commented: Approved =) +1
CoolGamer48 65 Posting Pro in Training

You would actually name the file myFile.h, not myFile.cpp. When you #include something you are basically taking the contents of the header (*.h) file and dumping them into your current .cpp file. If the file you need to include is in your current working directory (or if you're specifying an absoltue path), use "". If the file is in one of your compiler's include directories, use <>.

It is a bad idea to define functions in a header file. If you have this in myFile.h:

int MyFunc()
{
    return 5;
}

and you have two .cpp files in your project, and they both #include myFile.h, you'll get an error, because you're trying to re-define a function, a no-no. Instead, have prototypes in your header files. Like:
myfile.h

int MyFunc();

and have definitions in a .cpp file:
myfile.cpp

#include "myfile.h"

int MyFunc()
{
    return 5;
}

Then any amount of other files can #include myfile.h with no problem, as long as myfile.cpp is also in the project.

One last thing, it's good to put the code in your header files in #ifndef blocks. Like this:

#ifndef MY_FILE_H
#define MY_FILE_H

int MyFunc();

#endif

This way, if you end up #including the same file twice in one .cpp file (which can happen when you have lots of #includes), you won't have an issue, since the code is only executed once.

William Hemsworth commented: Nice post, easy to understand :P +2