nullptr 167 Occasional Poster

I'm not 100% sure I understand the question, but this seems OK and avoids any crashes.

#include <iostream>
using namespace std;

int main()
{
    int A[10][10], row, column;

    for (row = 0; row < 10; ++row)
    {
        for (column = 0; column < 10; ++column)
        {
            // avoid divide by zero
            if (column != 0 && row % column == 0) 
            {
                A[row][column] = row;
            }
            else
            {
                A[row][column] = column;
            }
        }
    }

    for (row = 0; row < 10; ++row)
    {    
        for (column = 0; column < 10; ++column)
        {
            cout << A[row][column] << " ";
        }

        cout << endl;
    }

    cout << endl << endl << "press Enter to exit...";
    cin.get();

    return 0;    
}
nullptr 167 Occasional Poster

a more compact example , with some modifications.

#include <iostream>
#include <string>
#include <ctime>

void setSecretCode(char*);
using namespace std;

int main()
{
    char code[5]= {0};
    setSecretCode(code);
    cout << string(code) << endl;
    cout << "press Enter to exit...";
    cin.get();

    return 0;
}

void setSecretCode (char* code)
{
    string colors = "RGBYO";
    int pos;

    srand(static_cast<unsigned int>(time(NULL)));

    for (int i = 0, mod = 5; i < 4; ++i, --mod)
    {
        pos = rand() % mod;
        code[i] = colors[pos];
        colors.erase(pos, 1);
    }

    return;
}
nullptr 167 Occasional Poster

Link opengl32.lib and glu32.lib

nullptr 167 Occasional Poster

Did you set the value of y to 1 before entering the do/while loop?
Also you have:

if (y >= 1 && y <= 4)

as far as I can see y would always be greater than or equal to 1, so there's no need to test that condition.

nullptr 167 Occasional Poster

From tutorial 1 - "As you notice, you simply need to open the DOS Device Name using \.\<DosName>. You could even open \Device\<Nt Device Name> using the same method. You will then create a handle to the device and you can call WriteFile, ReadFile, CloseHandle, DeviceIoControl!"

Which part are you not understanding?

nullptr 167 Occasional Poster

These tutorials should cover what you need to know.

nullptr 167 Occasional Poster

You could also use -

void TransformUppercase(std::string&  s)
{
    std::transform( s.begin(),
                    s.end(),
                    s.begin(),
                    ((int(*)(int))std::toupper));
    return;
}
nullptr 167 Occasional Poster
nullptr 167 Occasional Poster

Though your code is not strictly c++, this cuts down on some unneeded code.

int** PntrFunc(int** itemGiven)
{
    **itemGiven += 500;
    return itemGiven;
}

int main()
{
    int * pntr = new int;
    *pntr = 50;

    int ** mPntr = PntrFunc(&pntr);

    printf("result %d\n", **mPntr);
    delete pntr;

    "press Enter to exit\n";
    getchar();

    return 0;
}
nullptr 167 Occasional Poster

Just taking the first part of the equation - 3x^3
To multiply you need to use * as in 3*x
^ is bitwise xor, do you really want to calculate 3 times x xor 3?

nullptr 167 Occasional Poster

yeah, I need to go to bed, obviously what I wrote breaks the loop when pressing y or Y.

    do
    {
        // main code body

        std::cin >> cont;        
    } while (cont == 'y' || cont == 'Y');
nullptr 167 Occasional Poster

@pyTony, TY yes you're absolutely right. Corrected code -

do
{
    // main code body

    std::cin >> cont;        
} while (cont != 'y' && cont != 'Y');

return 0;
nullptr 167 Occasional Poster

The recursive call to main() at line 71 is not a very good idea.
You'd be better off using a do/while loop.

do
{
    // main code body

    std::cin >> cont;        
} while (cont != 'y' || cont != 'Y');

return 0;
nullptr 167 Occasional Poster

The first arg will either be the program name or empty, it's the second arg that will contain "-verbose", so you'll need to check that argc == 2.

nullptr 167 Occasional Poster

try this:

int main()
{
    char* array[4] = {
        "one", 
        "two",
        "four",
        "nine"
    };

    char* test = "four";

    check(test, array);
    getchar();

    return 0;
}



void check(char* test, char* array[])
{
    int i;

    for (i = 0; i < 4; i++)
    {
        if(strcmp(array[i], test) == 0)
        {
            printf("same string: %s\n", array[i]);
        }
        else
        {
            // whatever
        }
    }
}
nullptr 167 Occasional Poster

Just using the first example:
y >> 16 & 0xFF0 // y is shifted right by 16 bits, then bitwise and with bitmask 0xFF0

e.g 0xBEEFC000 >> 16 = 0xBEEF
0xBEEF & 0xFF0 = 0xEE0

nullptr 167 Occasional Poster

In your first post, when comparing two char pointers, you'll return the one with the higher memory address. In the second post, you're just comparing the first character of each string, which will return whichever character is alphabetically greater, though it's still not going to perform a string comparison.
I think you're just going to have to write the overloaded functions and define the data type, in order to perform the correct type of comparison.

nullptr 167 Occasional Poster

An example with no error checking or optimization.

void squeeze (char c, char S[])
{
    int i = 0;
    int j = 0;
    char fwd[MAX];
    memset(fwd, 0, MAX);

    for ( i; i < MAX; i++)
    {
        if ( S[i] != c )
        {
            fwd[j] = S[i];
            j++
        }
    }
    memcpy(S, fwd, MAX);

    printf ("%s", S);
}

Look up fgetc and fgets for your input and call the functions as suggested above.

nullptr 167 Occasional Poster

Try this:

    // int terminalArray[12] = {0};
    int histArray[10] = {0};
    int minValue;
    int maxValue;

    for (int j = 0; j < 12; j++)
    {
        minValue = 1;
        maxValue = 9;

        for (int i = 0; i < 10; i++)
        {
            if (terminalArray[j] >= minValue && terminalArray[j] <= maxValue)
            {
                ++histArray[i];
            }

            i == 0 ? minValue += 9 : minValue += 10;
            maxValue += 10;
        }
    }
nullptr 167 Occasional Poster

What is the declaration of terminalArray?

nullptr 167 Occasional Poster

A more compact version of your current code (untested)

int histArray[10] = {0};
int minValue;
int maxValue;

while (terminalArray >= 1 && terminalArray <= 99)
{
    minValue = 1;
    maxValue = 9;

    for (int i = 0; i < 10; i++)
    {
        if (terminalArray >= minValue && terminalArray <= maxValue)
        {
            ++histArray[i];
        }

        i == 0 ? minValue += 9 : minValue += 10;
        maxValue += 10;
    }
}

minValue = 1;
maxValue = 9;

for (int i = 0; i < 10; i++)
{
    cout << "\"" << minValue << "-" << maxValue << ": " << histArray[i] << "\"" << endl;
    i == 0 ? minValue += 9 : minValue += 10;
    maxValue += 10;
}

cin.get();

return 0;
nullptr 167 Occasional Poster

You required to write definitions for the given 4 function performing task in the program.

Have a go at writing the functions, then post your code and explain what you're having trouble with.
**when you post any code, select the code portion and press 'Code' in menu.

nullptr 167 Occasional Poster

string nom[100];
int num[100];
int cla[100];

With the method used to specify the arrays, it's impossible to actually delete an entry in the array. It seems from
your code that I briefly looked at, you're sorting the arrays, performing a binary search for a particular item
and if found you want to delete it.

Seeing as you're sorting the arrays, possibly the easiest solution to implement would be to overwrite the data for the
'deleted' items with the data from either the previous or next array items, meaning that you'd just have duplicate entries
in the array.

nullptr 167 Occasional Poster

Check that the return value of the following is a valid pointer :

OUTPUT_FILE = fopen(file, "a+");  // what is file?
nullptr 167 Occasional Poster

correction: line 8 should be printf("null\n");

nullptr 167 Occasional Poster

A slight modification of my code to print null.

void printukas1(treeptr mytree, int n)
{
    int i;
    if (NULL == mytree)
    {
        for (i = 0; i < n; i++)
            printf("\t");
        printf("null");
        return;
    }

    printukas1(mytree->rajt, n + 1);

    for (i = 0; i < n; i++)
        printf("\t");
    printf("%d\n",mytree->data);

    printukas1(mytree->left, n + 1);
    return;
}
nullptr 167 Occasional Poster

This code is the same as mine

No it's not. My code will print the tree regardless of its balance and display the tree as it actually is.
(within the limitations of std console output)

nullptr 167 Occasional Poster

Just specify the precision for your float values as %.2f

nullptr 167 Occasional Poster

This will work but only display as you depicted if the tree is balanced. e.g if
input values were like {4, 2, 6, 1, 7, 3, 5}

void printukas1(treeptr mytree, int n)
{
    int i;
    if (NULL == mytree)
    {
        return;
    }

    printukas1(mytree->rajt, n + 1);

    for (i = 0; i < n; i++) 
        printf("\t");
    printf("%d\n",mytree->data);

    printukas1(mytree->left, n + 1);

    return;
}
nullptr 167 Occasional Poster

I haven't tested, but check where I've commented.

for (i=0; i<sum; i++) {
differenceSquared = pow(userArray[i] - mean, 2); // at this point mean is still 0.0
sumTwo = sumTwo + differenceSquared;
}
// call function to calculate mean
mean = meanStandDev(sum, userArraySize);         // mean calculated after it's needed
nullptr 167 Occasional Poster

Untested, but should work.

void printukas1(treeptr mytree) // in order traversal
{
    if (NULL == mytree)
    {
        return;
    }

    printukas1(mytree->left);
    printf("%d\n",mytree->data);
    printukas1(mytree->rajt);
}
nullptr 167 Occasional Poster

See solution below

nullptr 167 Occasional Poster

This should work for you. :)

#include<iostream>

using namespace std;

class base
{
public:
    virtual ~base()
    { }

};

class derived: public base
{
public:
    ~derived()
    { }

};

int main()
{
    base *bptr_1 = new derived(); // should check that memory allocation was successful
    base *bptr_2 = new base();    // as above
    derived **dptr;               // double pointer

    try
    {
        dptr = reinterpret_cast<derived**>(&bptr_1);
        if(*dptr == NULL)
        {
            cout<<"(1) base ptr1 not pointing to derived"<<endl;
        }

        delete *dptr; // deleting memory allocated for bptr1.

        dptr = reinterpret_cast<derived**>(&bptr_2);
        if (*dptr == NULL)
        {
            cout<<"(2) bptr_2 not pointing to derived"<<endl;
        }

        cout<<"delete derived ptr"<<endl; // deleting memory allocated for bptr2.
        delete *dptr;
    }
    catch (exception& err)
    {
        cout<<"error caught :"<<err.what()<<endl;
    }

    system("Pause");

    return 0;
}