rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Show your code here, some explanation of your problems, and we may be able to help.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Some years ago I wrote a bunch of code to generate any number of primes. I used the Sieve of Aristhostenes to generate all the primes up to 10K or so and then used a recursive algorithm to determine primes beyond that. I would write them out to disk, and memory use was small - I did this on an old Compaq PC with 640K RAM, back in 1984-1985. It was computationally intense, but I had an 8087 chip which let me deal with large numbers up to 32-bits without problems (unsigned long integers of the time) and quite efficiently - IE, primes up to 4 billion. Today, you can use 64-bit unsigned integers for a googleplex of primes. :-)

And don't ask me to post the code here. I still have it on a floppy disk somewhere, but I currently have no functional floppy disk reader.

マーズ maazu commented: So, you have done the math decades ago. Would you consider investing in Primecoins? a variant of bitcoin. +0
rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Try using strcpy() and strcat() instead, as in:

if (buffer != 0) // test for a null buffer pointer.
{
    ::strcpy(buffer, w);
    ::strcat(buffer, v);
}

Yes, these are C functions, but they work just fine with C++ and are appropriate as your function arguments are simply char* and not std::string& or std::string* objects.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

What Moschops said, but you can have multiple versions of gcc installed on your system. The command shown will be the default version installed on your system. I have both 4.4.7 (default) as well as 4.7.2 installed. At Fermi National Laboratory, they are running 4.9.1 by default as I understand (my wife works in the computing division there). That is the latest and greatest with the most C++14 support available, given the standard is still evolving.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Showing your code would be helpful also. The class you are trying to allocate an instance of, does it have a static new() method?

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Google analyzed the list and found that less than 2% of the entries were legitmate current gmail credentials (that's still about 100,000), and have informed those account that they need to update their password on next login. Here is the relevant article: http://arstechnica.com/security/2014/09/google-no-compromise-likely-massive-phishing-database/

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Fibonacci algorithms can be made interesting especially if you discuss some of the history. The algorithm for computing the Fibonacci sequence is simple enough, has tonnes of applications, and has copious examples in nature. Here are two wikipedia articles that may help: http://en.wikipedia.org/wiki/Fibonacci and http://en.wikipedia.org/wiki/Fibonacci_number

FWIW, I found that joining and participating in Toastmasters was extremely helpful in learning how to speak with confidence and clarity in public.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Another term for this is "scoping", in that the scope of the variable is until the block it is defined within terminates. That particular variable will take precidence over others of the same name that are defined outside of the block, including global variables.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

How you do this depends upon you compiler and operating system. Read the relevant documentation for you system on how to create a static or shared library.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Ok. And just what is your problem? You want us to analyze your code making untenable assumptions? Please get real...

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

So, what is your problem? Please be specific and show examples of why these methods aren't working for you.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Does it work? :-)

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

This is why we have such system defined macros as INT_MIN and INT_MAX, etc. Those will be set appropriately for the architecture of your system, 2's complement or otherwise. FWIW, for an 8 bit integer (char) value, you would use the SCHAR_MIN and SCHAR_MAX macros. Also, for Intel class processors, SCHAR_MIN == -128 and SCHAR_MAX == 127. The high-order bit is the sign bit which is why the range is -128 through 127 and not + or - 127.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

First, arguments on the command line are presented to the main() function via the argv string array. Next, process each argument (argc 0 is the command name, argc 1 is the first argument, etc) and convert each to an integer. IE:

cmdname 1 2 3 999 will pass 5 arguments (arg 0 thru arg 4) as in int main(int argc, const char* argv[]) so you need to iterate argc as an index in argv from 1 thru 4, as in:

for (int i = 1; i < argc; i++)
{
    int value = atoi(argv[i]);
    /* Do other stuff here, such as output of the value. */
}   
rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

We don't do your homework for you. Make an honest effort and post your code here when you hit a brick wall.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

You might also try /sbin/fsck.xfs, though I would suspect that it converts that into a call to xfs_repair. It may be worth a try, however.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

More clear now. Iterate through the string and with each 2 characters, convert to decimal using the strtol function, specifiying the base option as 16 (hex). That will give you the (signed) long value of the 2 bytes that you want. RTMP (read the man page) for strtol().

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

@diafol
Yeah. I've never met a deadline I couldn't exceed... :-)

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

This is why you need to read my tutorial about using PHP properly as an object-oriented language. Don't do this stuff inline. Build your data strings dynamically in a class method or a function first, then output it.

https://www.daniweb.com/web-development/php/tutorials/484310/why-you-dont-want-to-mix-php-and-html-directly

mattster commented: Too true..... +4
rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

You have posted this twice. Please DO NOT do that! I answered the question already... :-( If the double posting was in error, then I understand that this happens occasionally (fat fingers on the keyboard), but don't make it a habit.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Please show the entire header and source for the CMObject class.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

There is no rule. This issue is processor-dependent. Some will drop data when the shift results in an integer wrap-around event, and others will push the left-most bit to the right-most (or vice-versa depending if the operator is << or >>). IE, what happens on an x86 processor may be different to what happens on an ARM chip. Sometimes, you can set the chip to use either means, but not for all processors. This is DEFINITELY a case of caveat programmer!

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Ever hear of Google? Have you looked at the PHP documentation? Have you ever edited an image file before? Don't ask us to do your homework (or work-work) for you if you haven't made an effort to solve the problem. I had a work task assigned to me to build a cell phone proxy browser emulator in PHP, and I never had used the language before. I had to learn PHP, reverse engineer the browser HTTP protocols, and get it working. It took me two months, but it worked adequately to validate our phone test tools.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

IE, please show what is setting the 'ss' variable that you are checking. The loop you show doesn't explicitly set it. That said, unless ss is a global variable, this could result in an endless loop.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Also, use instances of the std::vector class, and use the push_back() method to put the data into the correct vector (odd vs. even). Then, when done with the input, you can use a loop with an iterator to output the data from each vector.

If you know the size of the array in advance, then you can use std::array, but the std::vector class is better for dynamically sized arrays. It will resize as necessary as you add members.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

This is as expected. The atoi() function stops at the first non-numeric character in the string, which would be the space. You can use the strtol() (string-to-long) function which allows you to pass the address of a char pointer which will be set with the location of the space in the original string, so you can continue processing as needed. More logic will be required for you to handle this appropriately, naturally.

BTW, I am trying to teach you how to fish, and not just give you one... :-) In any case, the proper signature for strtol() is this: long int strtol(const char *nptr, char **endptr, int base);

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Please show an example of data and your expected (desired) output.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster
  1. The loop for(i=0;i<=4;i++) should be for(i=0;i<4;i++)
  2. You should set a 'largest' variable as found and then output that after the loop has terminated. Following is how to do that.
  3. You also have a bunch of other issues that should make your compiler throw up...

    #include<iostream.h>
    int main(void)
    {
        int arr[4]={23,38, 81,12};
        int biggest = 0;
        for(i=0; i < 4; i++)
        {
            if(arr[i]>biggest)
            {
                biggest = arr[i];
            }
        }
        cout << "largest integer is" << dec << biggest << endl;
    }
    
rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Huh? Please explain more clearly/completely.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Don't know. My wife just upgraded to Mavericks. I'll repost here if she has similar issues. Myself, I don't use Apple cruft. My wife on the other hand is an Apple fan-girl... :-)

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

state -> event -> transition -> new state. This is the short version of how FSM (Finite State Machines) work. The system starts in some state, gets an event, evaluates what state to transition to, possibly doing some work during the transition.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

I'm not familiar with this tool, but since it is generating binary executables my experience shows that when it works in debug mode but not production mode (segfaults, etc), it is due to the fact that debug mode pads arrays and such with extra memory. As a result, you might consider buffer overflows as a cause of this problem. IE, you need to analyze your code to see if you need buffer and array sizes to accomodate string terminator (null bytes) and similar.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

There are a number of methods to do this. There are native MySQL API's for C, ODBC, etc. Go to the MySQL web site for all the information you need: http://dev.mysql.com/

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

There has been an ongoing in-depth analysis of TrueCrypt from the security perspective and so far it appears to be pretty clean. I think ongoing support will be re-established once the analysis is complete. It is available, but just not being actively updated until the survey/analysis is complete. At least that's what I understand.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

This is what you should use: for (i = numwords-1; i >= 0; i--) {...}

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster
  1. Convert number to string.
  2. Create array of pairs in the string.
  3. Convert array members to integers.
  4. Iterate array to find largest member.
rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

@diafol
I think both using classes as well as templates have their uses. I haven't yet delved much into templates, so the question is a good one, encouraging me to do some research on that subject. Veedeoo's comment certainly helps in that regard as well.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

I appreciate any and all comments that help expand upon what I wrote for this tutorial. Writing good web code is not simple or straightforward, and many sites are vulnerable to hacking and malware infections because proper diligence is not applied to the code. Hopefully this thread will help steer web developers in the right direction.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

PHP is an object-oriented language, based (loosly) upon C++. It has classes, methods, member variables, and all that other good stuff. It runs on your web server, not in the client, but the HTML, JavaScript, and other stuff such as CSS blocks that it emits with its output commands are run on the client.

The purpose of this tutorial is to explain why you don't want to mix your PHP and HTML, JavaScript, etc. One reason is if you do that, it becomes pretty much impossible to debug. Another is that is it inefficient.

  1. Use classes and methods to build up your output HTML strings from the logic, passed $_GET, $_POST, and other global variables, and ONLY output them once they are completely formed.
  2. This allows you to recursively call (include) the same PHP code from forms that are created and output, providing you the capability to get some really complex stuff working that would be impossible otherwise.
  3. You can better validate passed variables, SQL query predicates, etc.
  4. If needed, you can emit debug data when inside your class member functions that would not be visible if you tried to do that when inside a JavaScript block of code.

So, don't mix PHP and HTML, etc. Build your output strings inside your PHP class functions and only output them once you have finished.

Example (mostly pseudo code):

<?php
    class MyClass {
    public
        $output = '';
        $debug = false;
        function __construct() {}
        function __destruct() {}
        function display()
        {
            echo "$output"; …
rubberman 1,355 Nearly a Posting Virtuoso Featured Poster
  1. Properly indent your code so it is easier to read.
  2. You probably didn't check for a NULL value, resulting in the crash.
  3. Item 2 above (null value) is not uncommon in binary trees.
rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Put #endif // !RoomOne_H at the end of RoomOne.h and don't include RoomOne.h in StoneAdventure.h

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

I've never had a problem installing it on Linux. What issues are you encountering?

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

If the MBR was borked, then it is likely the disc is fried and your attempts at recovery will be for naught. You need to run a sector scan on the drive to see if there are too many bad sectors. Is this a hard drive, or an SSD?

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

The question is whether it has really stopped charging, or if just the charging icon is not being properly updated. With the battery fully charged, try running the game long enough that if it isn't charging when you stop running the game (shut it down completely), you will see that the battery is no longer fully charged. If that is the case, and only this game causes the problem, then it is something in the game software that is telling the system to stop using the external charger (or to use battery only). In such a case, you need to report it to the game developer.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Just remember, that inserting already sorted data into a pure binary tree (b-tree) will result in what is effectively a linked list, with unoptimal search characteristics. Once you are able to build a b-tree, then consider building a balanced binary tree. The insert algorithm is more complex as it has to rebalance the tree when necessary, but it will always provide an optimal search performance. This is especially useful for large sets of data. The seminal treatise on this subject is Knuth's "The Art of Computer Programming - Volume 3 - Sorting and Searching".

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Class assignment? Sorry, but we don't do your homework for you. What kinds of classes do YOU think you need? Yes, I could give you a list (I was a shop foreman at a dealership once upon a time), but that would deprive you of the fun!

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

When something like this happens, the first thing you do is a full system reset - usually by shutting down the system cold, removing the battery (and no wall-plug connection), and then holding the power button down for some period of time (10 seconds to 1 minute). If after reinstallation of the battery and rebooting the system you still can't get in, then you need to do a full cmos/flash wipe. In that case, you will have to pull the keyboard to get to the motherboard, and (again with system shut down and battery removed) short out a couple of pins for a few seconds. Which pins depend upon the motherboard and you will probably need to get that information from the e-machines support web site. They may have better advice on how to do that for you.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

The main point of LFS is to teach people the inner secrets of configuring and building Linux systems from scratch (so to speak). If you want a light-weight apache server, then it would be better to get a light-weight Linux distribution and install apache and necessary other components there. Gentoo is a good choice (but will still make you tear your hair out most likely) in that you can configure it for just your hardware and install just the software you want. I have done that in the past and it was small, fast, and reliable. It had no drivers that were not needed, and only the software I wanted (aside what is necessary to run the system).

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

My guess is that there is a hidden file in the directory which the shell is not able to expand, resulting in the error. Check for that.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Unfortunately the link is no longer active so I can't say whether or not it may be appropriate for you. In any case, a usb device should suit you well.