thelamb 163 Posting Pro in Training

It is unsafe, that is why you want to use the _s variant. But the _s you need to use a little differently, because you need to hand over the size.

Remember that C-style strings are null-terminated, so strcpy will copy until it finds a null-char.

Anyway, I suggest that you change your code to use C++ strings instead of working with bare C style char arrays.

thelamb 163 Posting Pro in Training

errno_t strcpy_s(
char *strDestination,
size_t numberOfElements,
const char *strSource
);

You forgot the number of bytes you want to copy.

thelamb 163 Posting Pro in Training

What doesn't look good?

This is a pretty awesome assignment, you have several options:

Assuming the teacher doesn't have any kernel-level hooks you could create a driver that attaches to the process (look at KeStackAttachProcess) and reads from there.

Another approach: inject a DLL into the process that does the reading, and for instance writes to a file. This normally would require the use of OpenProcess and WriteProcessMemory but there are DLL injectors and DLL injection techniques that do not need this.

Or, a safe approach:
Use up all of your RAM, so that the OS starts paging out some memory pages (make sure paging is enabled). At some point it will page out your teachers program and you can read what you need from the page file. Of course this requires you todo some research into paging.

I would go for the kernel driver ;)

thelamb 163 Posting Pro in Training

That's not much more info than the first post.

- Why can't you use RPM?
- Are there other limitations? E.g. can you use something that requires admin rights?
etc.

thelamb 163 Posting Pro in Training

Tell us what you need to do please, without knowing some more details it's hard to suggest something.

thelamb 163 Posting Pro in Training

Hmm, both errors are fairly obvious (don't take that the wrong way ;)).

Look how you declare newStudent, it takes one Student object, by reference.
In the while loop you give it a Student* and an index.

Do you understand why in this case userData is a pointer:

Student userData[2];
newStudent( userData );

If not, I will explain.

So to summarize: You need to hand over the ith element of userData to newStudent, where i is the index.

Now the cin problem.
I'm trying to find the words to explain what it is that you're doing wrong... but I fail to find them so I'll just show you how it should be done:

int iScore;
cin >> iScore;

userData.setScores( iScore );

This is, although working, not a 100% correct solution, but if you understood my first post correctly you should be able to spot what you still need to do to make it better.

thelamb 163 Posting Pro in Training

How would you do this if p was a 1 dimensional array? It doesn't make sense to try and work out how 2D arrays work unless you have good knowledge of 1D arrays.

So show us that you can do this with a 1D array, then I'm sure we can come up with a solution for a 2D array from there.

thelamb 163 Posting Pro in Training

You expect 9 variables, but the line only contains 8. Plus, the types that are in the file must match the types of the variables. E.g. if the line is

"hello"

Then:

int firstWord;
file >> firstWork;

won't work.

Lastly, you should put extra braces around the file >> etc. >> etc.:

while( (file >> idnumber >> contact >> name >> street >> parish >> country >> category >> booking >> idtype) )
thelamb 163 Posting Pro in Training

First of all, I'd like to congratulate you on making a good post, we don't see it too often anymore around here!

Firstly, I would rename 'getStudent' to 'newStudent' or something simmilar, I think it reflects the purpose more accurately.

Now, newStudent is responsible for gathering all the information needed to create a new student, imho it should also be responsible for increasing the student count.

Q: When to increase the count?
A: When you have all the information, e.g. after getting the 5 grades.

The count is a static variable in the student class, so you can simply increase it with:

Student::count++;

You will however get a link error with the above source, having to do with the static count variable... but I don't want to spoil finding the solution for you just yet ;).

Now, you want to construct a loop in main that asks the user for student structures, until the max number of 25 is reached or until the user is finished.

I would personally write something like:

for( int i = 0; i < 25; ++i )
{
    if( false == newStudent( userData[0] ) )
         break;
     char cont;
     cout << "Add another student? [y/n]";
     cin >> cont;
     if( cont == .... etc )
}

I hope that helps.

You can add some if( i == 24 ) in the for loop, and tell the user that the maximum number of students has been reached.

thelamb 163 Posting Pro in Training

I'm not entirely sure if put overwrites the content at the current position (although I see no reason why it shouldn't). Can you try using f.write with a size of 1 ?

thelamb 163 Posting Pro in Training

You should make calcArea a pure virual funtion, by defining it as:

virtual void calcArea() = 0;

Right now the compiler thinks that this function is unimplemented. The calcArea in the derived shapes don't necessarily need to be virual.

thelamb 163 Posting Pro in Training

It means that >> will return a reference to its base class, in this case istream. This allows the programmer to 'chain' >> together:

cin >> iTest >> cTest >> iTest2; etc.

thelamb 163 Posting Pro in Training

Here's a beginning:

int main( int argc, char** argv )
{

   return 0;
}

Now, please show some effort and actually _try_ for yourself. If you then have specific questions how to do something, ask again (and SHOW us what you have done yourself).

thelamb 163 Posting Pro in Training

Why did you put the word double there? grossPay already returns a double.

So you can just remove the word double on line 10.

thelamb 163 Posting Pro in Training

'ticket' is an integer, but you expect your user to input 'A', 'B' etc.
What could go wrong?

You should check if the cin >> ticket is even succeeding, before trying to use 'ticket' in the switch case.

thelamb 163 Posting Pro in Training

How are you compiling? Do you use an IDE?
It seems that Node.cpp isn't being compiled (e.g. no Node.o is created).

thelamb 163 Posting Pro in Training

You want an array of size i, but i is a runtime variable. The compiler is giving you this warning because it has no idea how much space to allocate for Acts.

You should look up dynamic memory allocation, or re-design your solution using STL containers.

thelamb 163 Posting Pro in Training

C strings are 0 terminated, you are correctly creating the chars with size 81, and copying only 80 bytes to them, but what is the value of the last char? Exactly... it is garbage data.

So, you must initialize the char array to zero, you can do this in several ways:

char test[20] = { '\0' };
char test1[20];
test1[19] = '\0';
char test2[20];
memset( test2, 0x0, 20 );

I think this also answers your second question about str[0] = '\0'; ;), if not feel free to ask more detailed questions.

thelamb 163 Posting Pro in Training

Your cin >> in; (request the user for input) is outside the do...while loop.
So you ask input once and then it's continuously 'executing' the switch case with the same 'in' value.

thelamb 163 Posting Pro in Training

Lastly, the function that takes "Test" I believe takes a slightly bigger datatype than const char* try prefixing it with L--

That depends if the OP is building with Unicode or multi-byte support.

Intrade commented: Very interesting. Thanks for correcting me! +2
thelamb 163 Posting Pro in Training

There is an installer package for boost, it's mostly .1 version behind the latest build but that should not matter.

http://www.boostpro.com/download/

They support 2010, and allow you to install various builds (static multithreaded, dynamic multithreaded etc. etc. etc.)

And you're in luck... it is for the latest version ;)

thelamb 163 Posting Pro in Training

Next time also post the compiler error(s) you're getting ;)

thelamb 163 Posting Pro in Training

Exceptions do not exist in C, so including the stdlib won't do any good.
I don't know the exact details, but maybe Visual C++ accepts 'catch' without any specification as to what you want to catch, and g++ doesn't.

In any case, I suggest you specify what exceptions you want to catch, for example:

try {
   throw 1;
} catch( int e )
{ 

}

try {
    throw std::something;
} catch( std::exception& e )
{

}

try {

} catch( ... )  // Catches every C++ exception
{

}
thelamb 163 Posting Pro in Training

Everything is the same except the last parameter to 'transform'.

So why don't you pass this argument to 1 analysis function?

double analysis( const vector<Student_info>& s, type_of_last_param_to_transform t )
{
 ...
}

I've intentionally left out the type of the last parameter to transform, I assume you can find out what the type of that parameter is.

thelamb 163 Posting Pro in Training

The OP has not implemented a main function, not sure why you think he does.

int main(); // no function body
thelamb 163 Posting Pro in Training

You never define the body of the main function

thelamb 163 Posting Pro in Training

Your use of brackets indicates that you don't fully understand the do...while.
You're writing your code like:

do {
 ...something
} while( light == false );
{
 ...do something else
}

There are no statements in the do...while that will ever change the light boolean, and the part after the while( ... ); will only get executed once you break out of the do...while, which is never.

So you're probably looking to do something like:

cout << "you're in a dark room etc."
do {
    cout << "What would you like to do?\n";
    cin >> options;
    if( options == ... || options == ... ) {
        light = true;
        cout << "And there was light!\n";
    } else 
        cout << "The room stays as dark as it were\n";
    }
} while( light == false );

// Here, a correct option was given
thelamb 163 Posting Pro in Training

Never flush the input stream with fflush

fflush( stdin); // wrong!

There is a sticky on this forum that nicely explains how to deal with this problem.

thelamb 163 Posting Pro in Training

Think about what you're doing.
You know that if you want a max random value of 20, you do:
rand()%20;

So this will generate something between 0 and 20.
Now the problem starts when you try to deal with the min value, you simply add min(10) to the randomly generated number between 0 and 20.

So, what happens if rand()%20 returns 14?
14 is between 0 and 20 so that is absolutely possible.

thelamb 163 Posting Pro in Training

The 'math' in your if statements is very sloppy, it's hardly readable what's going on.

First off, why are you doing stuff like

if( (g.y/3)*3 == something )

g.y/3 * 3 is the same as g.y

So the two if reads:

if( g.y+k == g.y && g.x+l == g.x ) 

if( g.board[g.y+k][g.x+l] == g.board[g.y][g.x] )

So, now that things look clearer what exactly do you need to do?
- Take the element at [0,0], compare to every other element in the set.
- Take the element at [0,1], ...
- etc.

I think you can get that working.

Now, you say that the element that it currently being checked should not be checked to itself. Why not? Where is the harm?

If I check for duplicates in the array [ 0 1 2 2 ].
I'd take the first element 0, compare it to 0, 1, 2, 2 increasing a number when they are equal. At the end of this loop you can just say 'There are duplicates if I found more than 1 match'.

Hope that helped

thelamb 163 Posting Pro in Training

You are including gradebook.h from two files, so the compiler will parse it twice. By doing so it will throw errors because of something like 'XXX already defined in blabla.o'.

To prevent this, you should always 'guard' your header files.
So GradeBook.h should be:

#ifndef GRADEBOOK_H_INCLUDED
#define GRADEBOOK_H_INCLUDED

// All of the GradeBook.h content goes here.

#endif // GRADEBOOK_H_INCLUDED

Next time you post a question, please also post what errors you are getting. I foun this problem by reading your code, but it's possible that there are more errors.

thelamb 163 Posting Pro in Training

Huh? I think we have a miscommunication here ;)
By aligned I mean that the start of the variable names are at the same column.
I guess you meant aligned in memory?

// Not like:
int test;
string test2;

// But:
int    test
string test2;
thelamb 163 Posting Pro in Training

I find a lot of things important, here is a summary:

int myFunction( int arg1, int arg2 )
{
  if( 2 == arg1 ) // would throw error if I'd write 2 = argc1 by mistake
    return;       // And I generally thing it makes sense to write the constant                       on the left

   string myString = "Hello"; // Multiple variables are aligned
   int    test     = 5;
   int*   pTest    = NULL;    
}

int    myFunction     ( ); // Also aligned
string myOtherFunction( );

I tend to use NULL over 0, as it's the same anyway I find that using NULL shows the programmers intention better (don't start a war over this, it is my opinion that I'm not forcing on anyone ;)).

And yes, I mostly use m_ for my private variables, pure habit.

thelamb 163 Posting Pro in Training

I just write:

if( 2 == a )
    return true;

return false;
thelamb 163 Posting Pro in Training

You can't read the letter a from a file, and then assign a variable with the name a really dynamically.

I guess if the variable names that you read from the file are only a,b,c etc. you could put them in an array, using the integral value of 'a' as an index, it's not very elegant though.

You can also create a map<string,int> which maps the 'a' to it's integral value that you read from the file... I guess that would be a lot better.

thelamb 163 Posting Pro in Training

CreateThread doesn't take a pointer to a class's method, let's read the error message together:
Your argument type: 'DWORD (PMessenger:: )(void*)'
Expected arg type: 'DWORD (*)(void*)'

So CreateThread is expecting a pointer to a function that returns a DWORD and takes void* as argument. There are several ways to 'beat' this problem, because you cannot simply cast your function to a DWORD (*)(void*).

You can use a 3rd party library like 'boost', which allows you to use pointers to member functions to start a thread.
You can create a small 'wrapper' function like this:

DWORD start_ServerMsgThread( LPVOID param )
{
   PMessenger* pMsg = static_cast<PMessenger*>( param );
   pMsg->ServerMsgThread();
}

And start the thread like:

CreateThread( NULL, 0, &start_ServerMsgThread, static_cast<LPVOID>(this), 0, 0);

You hand over the SOCKET to ServerMsgThread, but you can just store this as a private member variable and access it from ServerMsgThread.
If you don't want to do this, you can create a structure with 2 members:

struct StartThreadStruct {
  SOCKET s;
  PMessenger* pMsg;
};

Allocate this, hand it over to CreateThread and from start_ServerMsgThread pass it to ServerMsgThread and access the SOCKET from there.

I hope that helps.

thelamb 163 Posting Pro in Training

Why do you want to convert the numbers to string first, and then back to integer?
I guess you want to do this so that from "93" you can get the 9 and 3 seperately and do the calculations... but that would actually prove that you haven't even read the assignment completely.

So... please read the assignment, and give it your best shot(you should be able to at least start) and then post again with what you have tried, and a _detailed_ explanation of where you are stuck.

thelamb 163 Posting Pro in Training

Now you are only looping once, and incrementing _both_ i and j _at the same time_.
Are you sure that you understand why your first solution, with 2 for loops, does not work?

thelamb 163 Posting Pro in Training

You first loop through i, and inside this for loop you loop through j.
So the sequence will look like:

i j output
0 0 "5a"
0 1 "5b"
0 2 "5c"
1 0 "5a"
1 1 "5b"
1 2 "5c"
2 0 "2a"
2 1 "2b"
2 2 "2c"

(I excluded the "-" and "+")

So... now you need to think of a way to fix that ;)

thelamb 163 Posting Pro in Training

Or look up the *_cast statements in C++.
e.g.
static_cast

thelamb 163 Posting Pro in Training

You're posting in the C++ section a question about VB.net ... please post it here:
http://www.daniweb.com/forums/forum58.html

Or a mod will probably move it soon...

thelamb 163 Posting Pro in Training

It does make sense, but your question is way too general. Based on you're post we have no idea how far you are... have you actually downloaded the information from the website already? Have you parsed it to get the individual items that you are interested in? etc. etc.

So please be more specific as to where the problem you're having is, and tell us what you have done so far.

thelamb 163 Posting Pro in Training

Not necessarily, everything you are assuming here depends on implementation details of the library.
It is unsafe, and bad practice to do this.

Why not check every function (provided that it returns something that indicates an error of course)?

You can still use the try/catch block to make life a little easier:

try {
    if( ! sftp->Connect(hostname, port) )
        throw std::exception( "Connect failed." );

} catch( std::exception& except )
{
    cout << "Exception! Message: " << except.what() << "\n";
}

*edit: cout is ofcourse only as an example.. if you don't have a console application this won't work out of course*

Then you should look at the libraries documentation if they provide any error-code that will give you more details about _what_ exactly went wrong.

thelamb 163 Posting Pro in Training

Are you sure this 'Chilkat' FTP library throws exceptions when something goes wrong? Maybe it is expecting you to check the return value of WriteFile etc.

thelamb 163 Posting Pro in Training

There is a new 'type' of framework, called the .net Framework 4 Client .. something.

It's much smaller because it doesn't include the server-side stuff that a client doesnt really need anyway. You can try to install this to see if it will work.
I'm no .net developer so I may be totally wrong but it is worth a shot.

thelamb 163 Posting Pro in Training

Your console application has some functions, that are probably called from the main() function.

This 'logic' you need to put in the GUI application, but instead of calling the functions from winmain you can call them for example when the user clicks a button on your GUI, and you pass as a parameter any configuration that the user did in your GUI.

I can't tell you what changes you have to make, because I dont know how you coded your Console app... but some obvious things like 'cout' won't work in the GUI app.

thelamb 163 Posting Pro in Training

Why would you want to keep the console application seperate? There aren't (m)any real world applications that spawn a new process to do some work and only use the GUI for configuration.

So just create one GUI project, and put the code from the console application in there... You will probably have to make some modifications but I would go that way.

If you decide to use CreateProcess anyway you don't need to store the configuration in a file, you can pass it as a command line parameter.
Just like you can create a process through cmd like:
>myProgram.exe argument1 argument2

thelamb 163 Posting Pro in Training

Probably because you didn't specify the namespace. nth_element is an std function so is only defined in the std namespace.

U have some options:
- Use std::nth_element
- Put using std::nth_element; after including the header file
- Put using namespace std; after including the header file (not a very sexy solution).

thelamb 163 Posting Pro in Training

vc_attributes is part of some CodeAnalysis 'framework' by Microsoft( http://msdn.microsoft.com/en-us/library/ms182036(VS.90).aspx ). Are you using someone else's code or a 3rd party library ? Or is it your intention to use this source code analysis/annotation ?

I develop for Linux and Windows so I use Code::Blocks (there is a new version out now, since 2 months.. it has improved a lot since the official version before this was 2 years old).

thelamb 163 Posting Pro in Training

"So I don't know what you mean by "complete abstract class" (I guess you mean what Java people call an interface class, which has no data members, no implemented methods, but only pure virtual methods)."

What else could I possibly mean?