mitrmkar 1,056 Posting Virtuoso

>> But what sort of error could be returned from either GetLastError() or ERROR_ALREADY_EXISTS for a program that hasn't even started running!?

Surely the program is running since we are talking about the return value of GetLastError() . (I don't quite get what you are saying there, sorry)

But, looking at the MSDN documentation, in case the named mutex has already been created;

If the mutex is a named mutex and the object existed before this function call, the return value is a handle (i.e. NOT NULL) to the existing object, GetLastError returns ERROR_ALREADY_EXISTS, bInitialOwner is ignored, and the calling thread is not granted ownership.

That should tell you what to check and how to interprete what GetLastError() returns.

mitrmkar 1,056 Posting Virtuoso

>> Many thanks as well

I'm not sure how to interprete this, but just note that your change:

>> I simply changed Line9 to:
>> if (GetLastError() != ERROR_ALREADY_EXISTS)

is not adequate. You really need to check what CreateMutex() returns along with what GetLastError() tells you.

[EDIT]
More discussion about the topic Avoiding Multiple Instances of an Application

mitrmkar 1,056 Posting Virtuoso

Would the OS or the compiler make a difference?

Your attempt is just a tad bit off, basically you could try

HANDLE H = CreateMutex(0, TRUE, _T("your_mutex_name_here"));

if(H == NULL)
{
    // Strict failure, GetLastError() will tell you more, perhaps ExitProcess()        
}
else if(GetLastError() == ERROR_ALREADY_EXISTS)
{
    // Prior instance detected, exit this instance.
}
else
{
    // No prior instance detected, execute the program.
    // The mutex will be automatically destroyed once the program exits.
}
mitrmkar 1,056 Posting Virtuoso

>> Tried that . Still not working.

What is the exact error message the prog displays?

mitrmkar 1,056 Posting Virtuoso

I suppose you ought to begin by changing your account information usage, i.e.

//// Instead of ...
//// pITask->SetAccountInformation(L"USERNAME",NULL); 

// .. use valid account information
pITask->SetAccountInformation(L"YOUR ACCOUNT HERE", L"ITS PASSWORD HERE");

See SetAccountInformation()

mitrmkar 1,056 Posting Virtuoso

OK, it looks like BankAccount has a default constructor whereas SavingsAccount doesn't have one. You might add default values for all SavingsAccount constructor's parameters (hence making it a default constructor) and retry.

mitrmkar 1,056 Posting Virtuoso

>> I thought I needed to add a constructor with no parameters but that didn't work or I didn't do it right.

Both SavingsAccount and BankAccount class need to have a default constructor in order for your allocation to succeed. Perhaps you wrote a default constructor for SavingsAccount but BankAccount doesn't have one?

mitrmkar 1,056 Posting Virtuoso

Your main() does not have the proper signature for taking arguments, you want to have ..

#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;

int main(int argc, char *argv[])
{
  ...

You might also want to check that argc is equal to (at least) 2.

SgtMe commented: Danke schon :D +2
mitrmkar 1,056 Posting Virtuoso

It (or any other tutorial) may come in handy later, if not immediately -- I tend to think this way, because you had obvious problems with basic C++ syntax.

mitrmkar 1,056 Posting Virtuoso

How about forgetting the extra array in main() (do you really need it at this point?), and instead go along the lines of ..

int main()
{
    srand(time(NULL));      // Seeds the random number generator
    Heap<int> heap;         // The Heap object
 
    while(!heap.isFull())
    {
        heap.insert(rand() % 190 + 10);
    }
    
    heap.display(); 

    while(!heap.isEmpty())
    {
        cout << heap.removeMax() << " ";
    }
    cout << endl;

    return 0;
}

>> tips to this Segmentation fault

You might use assert() as an aid in spotting out-of-bounds reads/writes. In other words, throughout your code, assert every access to the heap's array, like so

assert(index >= 0);
assert(index < mySize);
assert(parent < mySize);
assert(parent >= 0);
if (myArray[index] > myArray[parent])
mitrmkar 1,056 Posting Virtuoso

But I'm a little confused. I thought I did that with the 'SORTED ARRAY:' section ...

Yes, you did that correctly, however, I was suggesting that you might be stepping out of boundaries wrt. the heap's myArray[]

mitrmkar 1,056 Posting Virtuoso
void PLAYER::AddExperience(int amount)
{
    SetExperience(experience = amount);
}

I'd like to suggest a beginner-friendly C++ Tutorial.

mitrmkar 1,056 Posting Virtuoso

>> multiple definition of `Wait()'

This suggests that you have the statement #include "Helper.cpp" in one or more files -- you DON'T want to #include .CPP files.

mitrmkar 1,056 Posting Virtuoso

>> When I tried to put 'return maxItem;' out of the 'if' statement, the compiler is complaining about how maxItem is not defined. Is that what I'm supposed to do?

Strictly speaking: change your code so that you don't get that warning anymore.

About the boundaries, if you have an array of N elements, then you are allowed to access indices 0..N-1, inclusive, i.e.

const int ARR_SIZE = 3;
// An array, all elements initialized to zero
int array[ARR_SIZE] = {0};

for(int ii = 0; ii < ARR_SIZE; ++ii)
{
  // Do something with array[ii] here ..
}
mitrmkar 1,056 Posting Virtuoso

Alright, your project includes only the main.cpp file, through which you try to include another source file -- that is wrong. Generally, only include .h files in .cpp files.

Basically you want to add your source and header files to your Code::Blocks project so that they are visible in the Manager View. Then, when you build the project, the source files will get compiled (without being included anywhere). When setting up the project, try to do it in manageable steps (read: your code compiles), instead of adding everything at once and having maybe a hundred errors or so.

As to the semicolon-problem you are having, I cannot reproduce it (compiling your project as-is) - the only error was about undefined reference to Crossroads() , which is correct.

mitrmkar 1,056 Posting Virtuoso

>> ok i did and here is wht happens

Duh, something is amiss here, you might as well zip the project (*.h, *cpp) and post it as an attachment.

mitrmkar 1,056 Posting Virtuoso

Aha .. as a matter of the fact, you absolutely have to put that semicolon there i.e.

#include "Library.h"

//HELPER FUNCTIONS

void Wait()
{
    cout << "Press ENTER to continue\n" ; // <--- semicolon required by C++

    cin.ignore(1);
}

Now, be sure to use the above helper.cpp and rebuild -- what happens?

mitrmkar 1,056 Posting Virtuoso

Hmm, this is going round in circles, I'm having hard time in believing that the semicolon is there properly placed (see the above post) -- could you post the helper.cpp file again?

mitrmkar 1,056 Posting Virtuoso

>> yeah the compiler says somethign is wrong

I see, could you post the error message?

mitrmkar 1,056 Posting Virtuoso

>> i tried that it doesn't work

So, you are getting a compiler error?

mitrmkar 1,056 Posting Virtuoso

That sounds confusing, I think the following should do ..

#include "Library.h"

//HELPER FUNCTIONS

void Wait()
{
    cout << "Press ENTER to continue\n" ; // <--- added semicolon

    cin.ignore(1);
}
mitrmkar 1,056 Posting Virtuoso

Pass the warning options on the commandline i.e. g++ -Wall -Wextra and first get a clean compile.

As to the surprise number, I believe you might be stepping outside array boundaries, which are 0..N-1, inclusive.

mitrmkar 1,056 Posting Virtuoso

>> error: expected ';' before 'cin'

The compiler seems to be spot-on here, you really need to add a semicolon before cin as suggested.
;)

mitrmkar 1,056 Posting Virtuoso

>> undefined reference to `Wait()'

In Code::Blocks, be sure to add the Helper.cpp file ( Wait() is defined there) to your project and rebuild. Do the same with the file containing Crossroads() .

The compiler is not seeing the definitions of these two functions at the moment.

mitrmkar 1,056 Posting Virtuoso

In ReHeap() , comparison is used instead of assignment ..

if (left < mySize && myArray[left] > myArray[root])
  largest == left; // <--- Wrong

You should catch this by enabling basic warnings, i.e. compiling with e.g. -Wall -Wextra .

Also in ReHeap() , check that left and right are not negative when indexing into the myArray .

mitrmkar 1,056 Posting Virtuoso

>> and these are the erros i get when i try ot compile it:
>> main.cpp:4: error: '::main' must return 'int'

See Should I use void main() or int main()?

mitrmkar 1,056 Posting Virtuoso

>> Debug Assertion Failed!
>> Expression: (((_Src))) != NULL

This interesting error message pops up because you are passing a NULL pointer as a second argument ( _Src ) to strcpy_s() -- you have to be careful not to do that. This NULL pointer is likely to originate from one of the strtok() calls.

Run the program in the Debugger and hit Retry/Break when the assertion occurs, then, view Call Stack and you'll be able to navigate to the offending line of your code.

mitrmkar 1,056 Posting Virtuoso

Quite likely your project is configured to use precompiled headers through "stdafx.h".
In other words, you'll need to change the order of your includes, in order for the compiler to see <mysql.h>.

You could try ..

#include "stdafx.h" // First stdafx.h

#include <cstdio>
#include <windows.h>
#include <mysql.h>

int main()
{
  MYSQL *conn;
}
jonsca commented: Nice going. +5
mitrmkar 1,056 Posting Virtuoso

Instead of being returned, bad_alloc gets thrown, see bad_alloc.

mitrmkar 1,056 Posting Virtuoso

>> it seems that the WM_CLOSE message is being sent to my program for some reason.

Your WM_SYSCOMMAND handling needs fixing. As of now, any WM_SYSCOMMAND with wParam not equal to SC_SCREENSAVE or SC_MONITORPOWER falls through to the next case, ending up in a PostQuitMessage (0); call.

mitrmkar 1,056 Posting Virtuoso

This pops up...Unhandled exception at 0x00be21e1 in Lab 11a.exe: 0xC0000005: Access violation reading location 0xfeeefeee.

Well, you delete [] everything you've allocated, and then try to use that memory -- obviously this will not work.
Rather do ..

... 
  SortNames(pNames, NumNames);
  cout << "After sorting the names" << pNames [NumNames] << endl;

  // Done with the memory, delete it ...
  for (i = 0; i < NumNames; i++)
    delete [] pNames [i];
  delete [] pNames;
mitrmkar 1,056 Posting Virtuoso

>> i have try to use while(scanned = scanf("%d", &week) != 1) Note that you have omitted two parenthesis, it should rather read

while((scanned = scanf("%d", &week)) != 1)

Otherwise scanned will only equal 0 or 1, (i.e. never EOF ).
Anyhow, you might post your most recent attempt.

mitrmkar 1,056 Posting Virtuoso

The loop attempts to get an integer from stdin storing this integer in week . If this succeeds, scanned , which stores the return value of scanf() , will equal 1 (because a single value was being scanned), otherwise scanned equals either zero or EOF (you might test how your scanf() works with various faulty input, including e.g. Ctrl-Z).

mitrmkar 1,056 Posting Virtuoso

There is a stack overflow apparently

To avoid consuming the stack space, make the array global or declare it static .

For example,

/* Statically allocated. */
double array_1[32000];

int main()
{
  /* Statically allocated, only visible inside main(). */
  static double array_2[32000];

  return 0;
}

You may want to see the /STACK linker option.

mitrmkar 1,056 Posting Virtuoso

A suggestion .. why not make use of the fact that scanf() returns the number of items read?
Something along the lines of the following ..

#include <stdio.h>

int main()
{
  /* Generally, initialize your variables. */
  int week = 0, scanned = 0;
  
  printf("How Many of The Total Weeks? ");

  /* Loop until one int has been scanned .. */
  while((scanned = scanf("%d", &week)) != 1)
  {
    printf("Input failure, scanned --> %d, weeks?\n", scanned);

    /* fflush(stdin) IS a bad practice, eventually replace it with something better. */
    fflush(stdin);
  }

  printf("Weeks --> %d\n", week);
  return 0;
}
mitrmkar 1,056 Posting Virtuoso

>> and yes i am using OpenProcess(CREATE_THREAD_ACCESS, FALSE, ProcessID);

A mere CREATE_THREAD_ACCESS is not enough, see CreateRemoteThread().

mitrmkar 1,056 Posting Virtuoso

>> error system was not declared in the scope

If the code involves a call to system(), then you need to #include <cstdlib> .

mitrmkar 1,056 Posting Virtuoso

>> no match for 'operaror!=' in 'user_input!=1'

If you want to retain user_input as std::string , then compare against appropriate string literals, e.g.

if(user_input == "1")
{
  // Option no. 1 selected
}
mitrmkar 1,056 Posting Virtuoso

>> When i put "string user_input;" JUST BEFORE cin>>user_input it will work

Line 8 is effectively a comment because you end line 7 with a backslash (it's called line continuation). So, delete the unwanted backslashes ..

#include <string>
int main()
{
  // declaring variables
  string user_input;
mitrmkar 1,056 Posting Virtuoso

>> The following part of code is failling at first free call (Line no.26) giving above error.

Please use CODE tags when you post code.

Valstruct.ch[i] = "Anand";

Change the above line to use strcpy() instead of the faulty string literal assignment. free() is attempting to free memory at the location where the string literal "Anand" is stored -- hence your error.

mitrmkar 1,056 Posting Virtuoso

There's a glitch at least in mergeArray() , if head is NULL , you end up doing head->next = newNode; -- I believe you know how to fix that.

xxunknown321 commented: Thnx so much +2
mitrmkar 1,056 Posting Virtuoso

You are misusing CheckTokenMembership() -- for an example, see MSDN CheckTokenMembership()

mitrmkar 1,056 Posting Virtuoso

It seems that this time you don't have the main() function (previously you had two!).
So, add one and see if you get any output.

#include <iostream>
int main()
{
  std::cout << "testing ...\n";
  return 0; 
}
mitrmkar 1,056 Posting Virtuoso

>> Below is the program for swapping variables without any extra variable.

May I suggest that you view for example this thread ;)

jonsca commented: Yes, thanks for pointing that out! +5
mitrmkar 1,056 Posting Virtuoso

Wait -- would a plain assignment suffice?

copyRow = vec2d[3];
mitrmkar 1,056 Posting Virtuoso

>> you also have to explicitly call the base class' operator =()

Nope. The default assignment operator(which shouldn't have been there in first place in C++) for the class will get suppressed automatically.

I don't quite get what you are saying. To be clear, I was saying that in the derived class, you need to explicitly call the operator=() of the base class. If you don't, the base class members will not be changed by the assignment.

struct derived : base
{
  derived & operator = (const derived & other)
  {
    if(this != &other)
    {
       // Do the base class first ..
       base::operator = (other);

       // .. handle this class' members ..
    }
    return *this;
  }
};
mitrmkar 1,056 Posting Virtuoso

>> unfortunately it still doesnt work..

I'm guessing that lines 83 and 84 are still wrong (assigning to local temporaries h and w ).

Furthermore, you also have to explicitly call the base class' operator =() in order to make the assignment fully work, this doesn't happen automatically.

mitrmkar 1,056 Posting Virtuoso

>> obvious coding problems?

The basic functionality is somewhat lacking, e.g. toBinary() would not output anything, given the input zero -- a do/while loop might work better.

>> It is a bit inconsistent because I didn't use the stack on the hex conversion.

Why not use a stack for that too? To print the hex digits, you could write a simple function or maybe use hex manipulator (if your assignment permits).

mitrmkar 1,056 Posting Virtuoso

>> why this function isn't displaying any results, please?

You initialize shiftAmt to -1 and the loop only executes when shiftAmt >=0 .

mitrmkar 1,056 Posting Virtuoso

>> the compiler screamed at me when I did that.

Sometimes that happens -- anyway, having that period there is certainly wrong. Are you sure there are ..

#include <string>
#include <iomanip>
#include <iostream>