Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Blame a medical condition rather than a corrupt system.

What system do you mean? Who says its corrupt? Just because you think so doesn't make it so. And what do you think the President should or can do about it? There is little anyone can do to keep someone from walking into crowded theater and start shooting, with the possible exception of using metal detectors like those used in airports. How far are we willing to go to prevent this type of incident every few years? Should be put armed guards at the entrences of every public place, such as bars, restaurants, theaters, nightclibs, etc ? Are you willing to fork out another two or three billion dollars per year for it?

As for this shooter, I'm all for death penalty in such incidents, mentally ill or not.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Scientists say the world is made up of protons, nuetrons and electrons. They forgot to mention morons. (Seen posted on Facebook)

codeorder commented: If that isNot the .secret.of.Me., Then it defines everything that I live for.:) +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You should never ever use gets() because it will allow you to enter more characters then the buffer can hold, excess characters are just scribbled all over memory and your program will crash. There are a couple ways to avoid that problem

  1. fgets() -- e.g. fgets(name, sizeof(name), stdin); The problem with fgets() is that it may append '\n' to the end of the string, which your program will have to remove. If '\n' is not present at the end of the string that means there are more keys in the keyboard buffer which your program needs to flush out.
  2. scanf() -- e.g. scanf("%20s", name);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

virtual functions allow derived class to override functions in base class(s). When the base class calls a virtual function the top-most derived class function is called. If you have a base class called Animal and a derived class called Dog, when Animal calls virtual function Speak() the function in Dog will get called. You can have another derived class called Cat, in that case Speak() from Cat will get called.

There also is something called "pure virtual" function. Its the same as simple virtual function except the base class does not implement it, one of the derived classes is required to implement pure virtual functions.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Your program looks nice but your use of boost library is probably not allowed in his program. It's like hitting a nail with a sludge hammer, way too overkill.

ModernC++ commented: If I don't use at least one function/class from boost (at least STL) in 50 lines of code I may explode +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You need to have another counter that stores the index value of the highest number then add another line to the if statement on line 20 to set that integer to the current value of i loop counter. Don't forget to put { and } around that if statement.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

wap??? huh? speak engligh please

Banfa commented: Erm pot kettle black? ;p +7
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

My computer has USB keyboard and mouse. After using the Windows installer to install Ubuntu on my system and rebooting, the duel-boot menu popped up where I can select either Windosw 7 or Ubuntu. The problem is that my keyboard doesn't work at that point because it is USB, so I can't change the selection.

Anyone know a work around? PS2 or serial keyboard is not an option because my motherboard doesn't have either port. Can I change the default option while in Windows then reboot, and do the same in Ubuntu before rebooting? If so, how?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Your program is missing { and } around the if statement because the if statement consists of multiple lines

if(numArray[i]%2==0)
{
    printf("%d", numArray[a]);
    total+=numArray[a];
}

Line 20 also has a problem: variable n was never declared, and the result will only be an integer because ave is an integer.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You don't need to decompile a compiled program just to read the strings, any program such as debug.exe will easily display that along with the hex values of all the non-text bytes.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I'm hoping for someone hopefully with a law background to give me an overview of what needs considering.

That's not advisable -- its similar to asking someone with a little medical training to give you advance about an operation. Go see a licensed lawyer for legal advice, and go see an MD for medical advice.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Do you guys miss having views?

No. I can live quite nicely without them.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You have to test for folders. Here's a code snippet that will show you how that's done

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Just change the loop so that i is initialized to sizeOfArray-1, and loop until i == 0

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

put a loop in main()

int main()
{
    while(1)
    {
       gi();
       display();
       eval();
    }
    return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Both those are declared in stdlib.h, not alloc.h. AFAIK alloc.h is a non-standard extension by gcc and MinGW compilers.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The error is much more serious than just clearning the input buffer. The loop that starts on lines 21 and 41 overflow the buffer by about 20 bytes.

fgets(&suit[i],3,stdin);

The buffer suit only contains 2 bytes of memory, but the i counter counts from 0 to 20. What is it supposed to do with bytes 2 thru 20? Answer: scribble all over your programs memory space then Crash.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Just replace the line 15 with this: cout << space << '\n';

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

My guess is that you failed to include <string> header file and/or code the using std::string statment.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here is a code snippet I wrote some time ago, maybe it will help you with your question. As for the sub-directory question, see the example in my code snippet -- you have to test for them.

The code snippet was written in c++, so just ignore the code you may not understand and concentrate on the loops.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The reason for the problem is because both FileTitle and FilePath are allocated on the stack, which disappears just as soon as the function returns. The solution is to pass the filename and path to the function as parameters so that they don't get destroyed when openFileDialog() returns.

BOOL OpenFileDialog(char*path, char* filename, bool InvertSlashes = false)



int main()
{
   char path[_MAX_PATH];
   char filename[_MAX_PATH];
   OPENFILENAME of = OpenFileDialog(path, filename);

 }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I just now noticed that change -- at first I thought my eyesight was going because everything got a lot dimmer. I don't find it annoying at all, now that I know its not just my eyes. It makes the ads stand out a lot better which might increase the click rate. I haven't seen this anywhere else -- maybe you should hurry up and patten the idea before others copycat it.

Nick Evan commented: Haha! +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

First you have to use a loop to find the negative value. Once found, start another loop to compare each of the values from the beginning of the array to the one past the negative number.

For example: let int i be a counter that finds the negative number. Let j be a counter the counts from 0 up to the value of i (where the negative value is located) Now, in a loop compare array[i[ with array[j], then if they are the same increment both i and j. If it gets to the end of the array then both arrays are identical.

And no, I won't write it for you -- its your job to figure out how to do it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 47: write(pipo, &arra[k], sizeof(arra));

Remove the & symvol -- arra[k] is already a pointer

line 55: free(arra[k]);

delete that line, arra can not be deleted.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Sounds like you need a course in c++, not Eclipse. Eclipse is just an IDE -- a programmer's tool, much like a hammer is to a carpenter. You don't learn how to build a house by asking how to use a hammer.

DeanMSands3 commented: Well said, sir. Well said. +4
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

For *nix read some of these threads

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The code you wrote is not reading the file.
Instead of MyReadFile.eof() do this, assuming MyReadFile is std::ifstream

std::string line;
while( getline(line, MyReadFile) )
{
   // blabla
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I dont know semaphores and threads

Then start learning. Read up on them then write a small program that illustrates how they work.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Neither of the code snippets you posted compile. This is your second example with a couple changes so that I could make it compile, but it also has a problem.

The operator << has two parameters, but main() is passing only one parameter. Fix that and both examples will compile.

#include <iostream>

using namespace std;
struct RGB
{
    int R, G, B;
};

inline std::ostream& operator << (std::ostream& Str, const RGB &Rgb)
{
    Str<<"R: "<<(int)Rgb.R<<"  G: "<<(int)Rgb.G<<"  B: "<<(int)Rgb.B;
    return Str;
}

int main()
{
    RGB Rgb;
   cout<<Rgb(16777215);      
triumphost commented: Thank you +5
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You can't actually code them as you posted them because the second line will produce a "redefination" error message. Once a macro has been defined you have to undefine it before it can be re-defined.

#define PRINT (a,b)cout<<(a)<<(b)
#undef PRINT
#define PRINT (a,b,c) cout<<(a)<<(b)<<(c) /*trouble?:redefines,does not overload*/

You don't have to define macros at the beginning of a program -- they can be defined, undefined, and re-defined anywhere you want to do it. The compiler will use the most recent definition when compiling the remainder of the program from the point that the macro is defined to the end of the program file.

Macros are evil beasts. One reason is because of what I just said above, that macros can be redefined anywhere in the program making it difficult for a programmer to figure out why something went wrong.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you just want the longest word then read the file one word at a time, not the entire line. Do that with fscanf(). After a word is read all you have to do is call strlen() to get the word's length and compare it with the length of the most recent longest word that was read in the past.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 11: start the value of j = i counter instead of 1

line 14: print the value of j not i, and do not increment it on that line. It will be incremented on line 11. Finally, put a space in the format specifier so that there is a space between the numbers printed on the screen.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Depends on the compiler you are using. If you are using Turbo C++ then you can't code the using namespace std: option because that compiler doesn't understand it. You have to use fstream.h with that compiler.

If, on the otherhand, you are using one of the modern c++ compilers then you have to use <fstream> -- without the *.h extension.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The whole purpose of the up/down arrows is to let members vote anomously and avoid giving rep. IMO its just as easy to enter a comment if you want to give rep and I see no reason to change the system.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

In C language, before version c99, you have to declare all objects at the beginning of the block. Reverse the order of lines 8 and 9 so that the declaration of pFile is the first thing in the function. C++ does not have that restriction.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Why do you need a tool to do that? Just use Windows Explorer, create a folder and copy the files into it. Simple.

adam_k commented: That's what I am doing and never needed a tool +8
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

why do you want to do that? I see no advantage of using pointers in that program, they could actually make it more difficult to read and comprehend the algorithm.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

she means that the parameters on line 15 and line 58 do not match. They have to be the same. Also, its best to always pass structures around by reference, never by value, because the program has to duplicate everything in the structure when it is passed by value. You are doing that for the input function, but not for the display function. Passing by value takes CPU time and can slow down your program. Of course it won't be noticeable in simple programs like you are writing, but it will have a performance hit on large programs. So you should get into the habbit of passing structures/classes around by reference now so that you don't have to unlearn bad habbits later on.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Possibly line 11 of main.cpp -- std: is a label, you want std:: (two colons, not just one).

The three set functions in the header file should be void functions because they do not return strings. Your compiler should be giving you warnings about that in the implementation *.cpp file., something like "function must return a value"

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

They should try throwing shoes like in other parts of the world, at least they have a better chance of re-using them.

You mean like this?

jkon commented: The problem with that is that it may exist a class “how to avoid shoes” in the corrupt politicians university ;))) +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I suggest this one, because ideally a compiler shouldn't crash no matter what you feed it.

Compilers often have bugs just like any other program. I've even had earlier versions of Microsoft compilers crash on me for internal compiler errors.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If x is a float or double printf() will think its an int because of the %d and try to print it accordingly. On 32-bit compilers the size of an int is 4 bytes while the size of a float is 6 bytes. You might even get strange results for all the other parameters because the float will screw up the order of the parameters on the stack. So if you have "%d%f" printf() will attempt to use some of the float as part of the string, which of course is wrong.

The main thing is to make sure the data types of the parameters match the items in the format. If x is an int then passing either x or &x might depend on the compiler you are using, because &x is a pointer. On some compilers pointers and ints are the same size, while on others, like Turbo C, they are different sizes.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The first thing I noticed while stepping (debugging) through your program is that you are pushing "." and ".." as well as other folder names onto the vector of files (see line 49). If the file is a folder then you don't want to do that.

Instead of main() passsing ".." to scan(), have main() call _getcwd() to get the current working directory and pass that to scan().

Then in scan(), the value of fullPath should just be the same as the parameter startDir

Here is the complete program I tested. Notice that I commented out a few things in main() that you may want to put back in. I didn't know what it was for su I just commented it out

#include <iomanip>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <ctime>     // ctime_s()
#include <io.h>          // _findfirst, etc.
#include <direct.h>
using namespace std;
vector<string> filesFound;

vector<string> scan( string const& filespec, string startDir, bool isRecursive )
{
    intptr_t hFile;
    _finddata_t fd;

    // fix directory name
    if( !startDir.empty() )
    {
        char last = startDir.back();
        if( last != '/' && last != '\\' && last != ':' )
            startDir += '/';
    }
    string findPath = startDir + filespec;
    string fullPath = startDir; //findPath + "\\";


    if( (hFile = _findfirst( findPath.c_str(), &fd )) == -1L )
    {
        cout << "No " << filespec << " files in current directory." << endl;
        return filesFound;
    }

    do {
        if( isRecursive &&
            (fd.attrib & _A_SUBDIR) &&
            fd.name != string(".") &&
            fd.name != string("..") ) …
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Only limited way can class A use class B before class B is declared, class A can declare a pointer to an object of class B but that's about the extent of it.

class B; // pre-declare class

class A
{
public:
   B* b; // declare a pointer to class B


};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I'm Christian, but I don't believe in the literal interpretation of the Bible. Instead I believe that the Bible was written in terms that the people at the time of its writing could understand and their understanding of the world around them. Since they had no knowledge of the Americas the great flood of Noah's time was probably localized to his area of the world. To my knowledge (which is very limited) there is no evidence of such a great flood on this continent.

DavidKroukamp commented: your words precede your reputation :) +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Your requirements are pretty steep (challenging) for someone brand-new to C++

My guess is that course is NOT intended for beginners. Most likely an advanced programming course for which the OP does not have the prerequisites. If it is a beginner's course then fire the instructor and drop the course.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

And we're forgetting one ... Congrats to Sanjay for being promoted to co-Administrator! :)

Does that mean we get to curse at him when things don't go right :) LOL Just kidding. Congratulations Sanjay. You have been one of the best contributors here and you deserve the promotion.

And congrats pyTony and ardav, now you have your work cut out for you.

~s.o.s~ commented: Thanks Melvin :) +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

1) Use 64-bit version of VC++, I think its version of fstreams support huge files

2) call win32 api read/write functions which support huge files (see ReadFile() and WriteFile())

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Dump that old ancient compiler and buggy IDE. Get either free VC++ 2010 Express or free Code::Blocks w/MinGW compiler. Both compilers will produce startup DLL projects for you.

Here is a tutorial

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

use fgets() instead of scanf() so that all the words get put into the string.

int main()
{
   char line[100];
   fgets(line, sizeof(line), stdin);
}