nucleon 114 Posting Pro in Training

Sleep a day at a time. Check the date/time every time you wake up.

nucleon 114 Posting Pro in Training

MyStudent.Name is the name of a storage location capable of holding up to 20 characters (including the terminating null character). You cannot simply assign a string constant to MyStudent.Name since that just tries to copy the address of the string constant to MyStudent.Name. What you need to do is copy the characters from the string constant into the space provided in MyStudent.Name. strcpy (MyStudent.Name, "Test Value"); (or strncpy for safety when using user input)

nucleon 114 Posting Pro in Training

I leave its improvement as an exercise to the OP. ;)

nucleon 114 Posting Pro in Training

In C++ this problem would usually be solved using a string and a map. Is there any reason you're not using these?

If you must use strtok and do not want to copy the tokens it finds but instead just point to them like you are trying to do, you will have to restore the null-character to the end of each token, since strtok writes the delimiter characters back.

nucleon 114 Posting Pro in Training

This deactivates the close option. Remember that you'll have to catch ctrl-C too.

#define _WIN32_WINNT 0x0500
#include <windows.h>
int main() {
  HWND hwnd = GetConsoleWindow();
  HMENU hmenu = GetSystemMenu (hwnd, FALSE);
  HINSTANCE hinstance =
    (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE);
  while (DeleteMenu (hmenu, 0, MF_BYPOSITION))
      ;
  system ("pause");
}
Ancient Dragon commented: Very Good :) :) +36
nucleon 114 Posting Pro in Training

Even though you store it in a double, you are still doing integer division because both operands to the slash are integers. Add a decimal point to at least one of them to get decimals. value = 1.0 / 2;

nucleon 114 Posting Pro in Training

Start by reading the code you've been given carefully and try to understand it (it would be too tedious to explain it here; consult your textbook). Then write a piece of the implementation (e.g., initialize the cave) and test it. Then write the next piece. Note that the cave is of type Room cave[][CAVE_SIZE] .

nucleon 114 Posting Pro in Training

It depends. In general you wouldn't have separate arrays, but a struct and then an array of that struct.

struct Employee {
    T1 salesID;     // whatever your types are
    T2 code;
    T3 numUnits;
    T4 numDollars;
};

Employee emp[numEmployees];

emp[5].salesID = 123;

Swapping emp[5] with emp[10] will swap all fields. Obviously if the record got much larger that would become inefficient, in which case you could sort an array of pointers to the array of structs (or array of record numbers for a file of records) and just move the pointers around.

nucleon 114 Posting Pro in Training

When you swap elements in the salesID array, swao the corresponding elements in the other arrays.

nucleon 114 Posting Pro in Training

Have you tried theForger? Also note that MSDN (Microsoft Developer Network) has full windows documentation and a generic sample application as well as a categorized list of API (Application Programmer Interface) functions. There is also MFC (Microsoft Foundation Classes), an object-oriented wrapper for the API, but you should probably learn something about the API first. This is all assuming you want to go native Windows (no 3rd party GUI framework, no managed code).

nucleon 114 Posting Pro in Training

I see. Thanks. Just started reading the standard. Kind of jumping around at the moment. Haven't read much about the library. Over 700 pages in the thing! I wasn't expecting that.

nucleon 114 Posting Pro in Training

Don't bother. Mine was "conceptually simple." Your bit-shifting solution is best. It's even a perfect candidate for coding in assembly if performance was an issue.

nucleon 114 Posting Pro in Training

You should profile them. Post your results.

nucleon 114 Posting Pro in Training

In the standard "16.2 Source file inclusion" (my first reference!) it mentions an interesting difference between <header.h> and "header.h". Basically, it says that the "" form may not even be supported, and if it isn't or if it is but the file is not found using that method, then it switches to acting just like <>.

The method (such as the order of directories) by which <> or "" look for "files" (or whatever) is implementation defined. I believe my imp. looks in the current dir first for "", but looks in the other imp.-defined places first for <>.

Also, don't the <iostream.h> forms automatically add a bunch of "using std::xxx" (brining all identifiers into the global namespace) while the <iostream> form does not? Doesn't seem to be in the standard, but that's what my imp. does.

nucleon 114 Posting Pro in Training

A first post homework dump.
Try filling in the functions a little.

nucleon 114 Posting Pro in Training

How tedious it is depends on how many different types you need to reverse. If just ints:

typedef unsigned char uchar;

union IntBytes {
    int i;
    uchar b[sizeof(int)];
};

WriteInt( int n, FILE* fout ) {
    union IntBytes uBytes;
    int i;
    uBytes.i = n;
    for (i = sizeof(int) - 1; i >= 0; --i)
        fputc( uBytes.b[i], fout );
}
nucleon 114 Posting Pro in Training

You're not linking with the other code file!

nucleon 114 Posting Pro in Training

You probably shouldn't be "going to main". Remove the return main(); part and change it to a loop.

nucleon 114 Posting Pro in Training

I have no idea. I haven't figured that one out. It looks quite a bit harder.

nucleon 114 Posting Pro in Training

You haven't initialized the local variables you use in main.

nucleon 114 Posting Pro in Training

Try moving your definition of flight schedule[] to the beginning of main.

nucleon 114 Posting Pro in Training

Narue, can you really dynamically allocate a static array in C99? Just seems odd. Is it only sized on the first call in your example?

nucleon 114 Posting Pro in Training

Can you install a newer version of the TurboC compiler? Or can you switch to a better IDE/compiler like MSVC++ or Codeblocks?

nucleon 114 Posting Pro in Training

It might look harder than it is. Here's an explanation of the first one:

Input: n
Start r at 0.
Loop n times (using index from 0 to n-1):
  * when index is less than n/2:
        add 1 to r (this is done n/2 times)
  * when index is equal to n/2:
        mul r by 2 (this is done once)
  * when index is greater than n/2:
        cube r (this is done (n/2)-1 times)

And so the equation is obvious. The second one is the same idea but a little tougher. You need to determine how many times each line executes within the loop.

nucleon 114 Posting Pro in Training

Try something like this:

#define MAXFILESIZE 120
...
char strFileString[MAXFILESIZE];
...
ReadFile(fh, strFileString, MAXFILESIZE, &dwRead, NULL);
CloseHandle(fh);

if (dwRead >= MAXFILESIZE) --dwRead; // so we don't write past the end
strFileString[dwRead] = 0; // ensure null termination of C-string

strncpy( strStartTime, strFileString, 11 );
strncpy( strWhateverTime, strFileString + 13, 11 );
// The + 13 skips the first 13 chars, the 11 reads 11 chars.
...
nucleon 114 Posting Pro in Training

You're mixing C-strings and the C++ string class. Here you just want plaing old C-strings, which do not have member functions associated with them, so you can't do the substr thing. Just do it in a normal old C way.

nucleon 114 Posting Pro in Training

Try reading 1000 bytes at a time with fread then.

nucleon 114 Posting Pro in Training

Does the size of a proc file make sense?

nucleon 114 Posting Pro in Training

InitCommonControlsEx (see the table at the bottom)
Try putting it in your WM_CREATE handler.

nucleon 114 Posting Pro in Training

You haven't posted the manifest file.
Did you InitCommonControlsEx() ?

nucleon 114 Posting Pro in Training

Here's the list of virtual key codes. jencas makes a good point that I was wondering about myself. Still, give it a try and let us know what happens.

nucleon 114 Posting Pro in Training

>That solution is basically like my original solution, and leaves me with input that never gets saved in the buffer that i made available for it.

Actually it isn't like your original solution. Differences:
1. yours consumes any characters, not just whitespace
2. yours consumes a line even when you don't want it to

Mine only consumes initial whitespace (incl. newline) leaving any non-whitespace to be picked up by the fgets. That doesn't mean it does what you want though!

Probably the best solution is to read all input with fgets and deal with the string so read (perhaps with sscanf). You could wrap fgets in a function that does two things:
1. Ensures the string is not only whitespace (if that's not allowed)
2. Removes the '\n' (if any) from the end of the buffer.

nucleon 114 Posting Pro in Training

That's very strange. I don't know what the problem is.

nucleon 114 Posting Pro in Training

StuXYZ: I didn't just READ your post, I studied it until I understood it because I found the situation a little confusing. It's actually pretty straightforward once you realize what the template class Foo<float>; in foo.cpp (from other thread) is doing.

nucleon 114 Posting Pro in Training

Here's a function that uses a set to remove duplicates from a vector without changing the order of elements:

void remove_dups (vector<string>& v) {
    set<string> s;
    pair<set<string>::iterator, bool> result;

    for (vector<string>::iterator i = v.begin(); i < v.end(); ++i) {

        result = s.insert(*i);

        if (!result.second) {
            v.erase(i);
            --i;  // adjust iterator
        }
    }
}

I'm not sure if the --i can blow up (although note that the first element will never be erased because it definitely will not be in the set).

robotnixon commented: thanks for the help +2
nucleon 114 Posting Pro in Training

You're going to have to give more info, and preferably less code. What (non-standard) libaries are you using? For example, is FGS_GetCurrentKeyCode() a library function? Also, what does this mean exactly: "once game is over then it is taking the values from keys".

nucleon 114 Posting Pro in Training

This seems to follow your solution but gives me a "multiple definition of void Output<unsigned int>(...)".

// main.h
#include "output.h"

int main () {
    std::vector <unsigned int> v;
    v.push_back (3);
    Output (v);
    return 0;
}
// output.h
#include <vector>
#include <iostream>

template <typename T>
void Output(std::vector<T> &V) {
	std::cout << "\nother\n-------\n";
	for (int i = 0; i < V.size(); i++)
		std::cout << V[i] << std::endl;
}
// output.cpp
#include "output.h"

template <>
void Output<double>(std::vector<double> &V) {
	std::cout << "\ndouble\n--------\n";
	for (int i = 0; i < V.size(); i++)
		std::cout << V[i] << std::endl;
}

template <>
void Output<unsigned int>(std::vector<unsigned int> &V) {
	std::cout << "\nunsigned int\n------------\n";
	for (int i = 0; i < V.size(); i++)
		std::cout << V[i] << std::endl;
}
StuXYZ commented: Template issue/well spotted. +5
nucleon 114 Posting Pro in Training

Alternatively to cin.ignore(...) and such tactics for consuming a leftover newline, you could use getline to read choice, thus not leaving any newlines in the input buffer.

nucleon 114 Posting Pro in Training

Check out post number 11 (by StuXYZ) in this thread (from earlier today).

nucleon 114 Posting Pro in Training

Here's one way to find the PID from the exe filename.

#include <windows.h>
#include <tlhelp32.h>
DWORD PID_from_EXE (char *exe_name)
{
    DWORD ret = 0;
    PROCESSENTRY32 pe32 = {sizeof (PROCESSENTRY32)};

    HANDLE hProcSnap = CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0);
    if (hProcSnap == INVALID_HANDLE_VALUE) return 0;

    if (Process32First (hProcSnap, &pe32))
        do
            if (!strcmp (pe32.szExeFile, exe_name)) {
                ret = pe32.th32ProcessID;
                break;
            }
        while (Process32Next (hProcSnap, &pe32));

    CloseHandle (hProcSnap);
    return ret;
}

Look up "DLL injection" for your other question.

nucleon 114 Posting Pro in Training

In essence your char array already has "hex" values in it, or decimal numbers or characters or however you wish to imagine them. Transferring them to another (unsigned char) array will not really change anything.

You should post what code you have to clarify your question.
(BTW, 0x03 is not the hex code for the character '3', it's 0x33.)

nucleon 114 Posting Pro in Training
nucleon 114 Posting Pro in Training

Prototypes go at the top of the program (usually).

You have an extraneous semicolon at the end of this line which causes it to not control the next line as you expect it to: if(CompareStrings(text[i], text[i+1]) == -1); Also, the indices you are using in the above line are entirely incorrect. They should be j and min, not i and i+1.

You seem to think that the "..n" gives a newline. Actually it should be "\n" (backslash n).

BTW, half the places where you use the number 10 you actually mean 20. If you had used your defined constants LEN and NUM you wouldn't have had that problem.

nucleon 114 Posting Pro in Training

You have to fill in the template to instantiate it: std::vector< foo< int, double > > bar;

nucleon 114 Posting Pro in Training

I'm not sure if this is what the errors indicate, but have you properly wrapped your C declarations like so:

#ifdef __cplusplus
extern "C"
{
#endif

int cfunc1( int n );
int cfunc2( int n );

#ifdef __cplusplus
}
#endif
nucleon 114 Posting Pro in Training

Open the file in binary mode: fp = fopen( filename, "rb" ); Read known structures and arrays with fread.
Read bytes with fgetc.

nucleon 114 Posting Pro in Training

The problem is that the OP has not yet written any code. This looks like code handed out with the assignment.

BTW, shouldn't the tab size for displaying code on this site be 4, not 8?

nucleon 114 Posting Pro in Training

Could you do something like this:

scanf( " " ); // Consume whitespace, if any (incl. newline)
  fgets( ... );
nucleon 114 Posting Pro in Training

Good point. Do a search for msg.exe.

nucleon 114 Posting Pro in Training

If you have done your program like above, but not run & edit program, then run & edit program, then ask specific question.

And use code tags.