mitrmkar 1,056 Posting Virtuoso

thanks...good advice. i really need to start with pseudo-code before jumping right into things. working out the array now. why is it not a good idea to use :goto:'s? by the way

Maybe search the internet for the topic "spaghetti code". Generally, first learn how to program without the 'goto' and then later on figure out the good uses of it.

Once you've done the pseudo-code part and start writing the code again, you really should consider grabbing yourself a decent compiler, which would be barking at you, given the above code. In other words, your current compiler is 'sloppy enough' to let you in for surprises. ;)

xavier666 commented: Lol spaghetti code! Didn't know about that one +1
mitrmkar 1,056 Posting Virtuoso

First thing to check in all of your code, how you are handling memory allocations/deallocations.

Now you are trying to free() variables that are on stack, that is ..

GLubyte TGAheader[12]={0,0,2,0,0,0,0,0,0,0,0,0};
GLubyte TGAcompare[12];
GLubyte header[6];
...
// Simply disastrous ...
free(TGAheader);
free(TGAcompare);
free(header);

You only free() what you have malloc()/calloc() ed, i.e. dynamic memory, nothing else.

PS. Since this is C++, you might be better of with new/new[] and delete/delete[] , respectively, if there's a need to use dynamic memory.

mitrmkar 1,056 Posting Virtuoso

Appears as if you are compiling it as C++ code instead of C.

PS. When you post code snippets, try including everything relevant to the given piece of code/errors. I.e. in this case, you most likely are including <stdlib.h>, but that does not show in the snippet (even little things can make a whole lot of difference in terms of the compiler output).

[EDIT]
In case of C++ compiler, you need to typecast the pointer returned by malloc() , in C, you don't have to do that.

Salem commented: Nice +19
mitrmkar 1,056 Posting Virtuoso

Is "copy" used by the language in some way that prohibits its use as a variable name in this situation

Yes it is, i.e. the std::copy algorithm. It gets pulled in via using namespace std; . So either change the name of the variable, or use your own namespace.

[EDIT]
PS. One more option would be to stop using the using namespace std; altogether and instead specify explicitly everything you use from the std namespace, so ..

#include <iostream>
using std::cout;
using std::cin;

and so on.

Salem commented: Agree with avoiding the using namespace catch-all. +19
mitrmkar 1,056 Posting Virtuoso

Yeah I was stupid and pressed (X) on all of the bars to the left you know the "Solution Explorer" I think and alot of more, how do I re-enable them?

Open the View menu, and select e.g. Solution Explorer, Class View and such.

mitrmkar 1,056 Posting Virtuoso

Yet one more thing, if/when you do strcpy(argv2, argv[1]); you want to check that there actually is an argument available, you can use argc for that.

mitrmkar 1,056 Posting Virtuoso

Oh, jonsca was fast, so I reduce this reply to state just the following:
A void function does not return anything. So it is an error to try to assign the function's return value to anything because there is no return value.

So you are supposed to use the function as

// Call the function (with existing arguments)..
sum(&x,&y,&z);
// .. now it's done the calculation, see what you got
cout << "sum: " = z << endl;
mitrmkar 1,056 Posting Virtuoso

Also, I am having a hard time remembering how to make so I can use a function that is further down the program. Instead of it saying it is undefined

You need the function prototype prior to its usage and the function definition later on.

// The prototype
int some_func();

int main()
{
  int xyz = some_func();
...
}
// The definition
int some_func()
{
  return 42;
}
mitrmkar 1,056 Posting Virtuoso

This looks like undefined behaviour

7.1.6.1

Except that any class member declared mutable (7.1.1) can be modified, any attempt to modify a const object during its lifetime (3.8) results in undefined behavior. Example:

<snip>

const int * ciq = new const int(3); // initialized as required
int * iq = const_cast<int*>(ciq); // cast required
*iq = 4; // undefined, modifies a const object

nezachem commented: Right, thank you. +1
mitrmkar 1,056 Posting Virtuoso

You might post the code that is not working (?).

Aia commented: That would have been the smart thing to do, you would think. +8
mitrmkar 1,056 Posting Virtuoso

undefined reference to `AboutDlgProc(HWND__*, unsigned int, unsigned int, long)@16'
ld returned 1 exit status

This is what i have at the "top" of the main.cpp

BOOL CALLBACK AboutDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam);

Now that you have declared the function, the next step is to implement it too, that is, you have to write the code for the AboutDlgProc() function (most likely in the main.cpp file).

I'm assuming that you are compiling some example project?

pato wlmc commented: Thanks, man you helped me alot +0
mitrmkar 1,056 Posting Virtuoso

It is more than just to get the pthread_create() syntax right. How about taking some time and going through pthread tutorial(s)

Salem commented: Indeed! +19
mitrmkar 1,056 Posting Virtuoso

'this' is always a pointer, so e.g. this.Year is wrong, it has to be this->Year . operator <() is 'const', that means that every class method you call inside it, must also be 'const', in this case it means getMonthInt() . Then again, you might directly access the .Month member variable.

To avoid unnecessary temporary objects, consider passing rhs by reference, i.e.

bool Date::operator<(const Date & rhs) const;
mitrmkar 1,056 Posting Virtuoso

Hey,
can someone tell me where I have to start?
I wanna make a program like cheat engine but I have no clue how :o...
Im not a beginner ( but also not an expert :P ) in C++(/CLI)...

What functions do I need?
etc. :p

Thx ;D

Mmmm, at the very least

int main()
{

}

;)

mitrmkar 1,056 Posting Virtuoso

Most likely GCC is unable to locate <stdarg.h>, just like <stddef.h> in your other thread. Something is wrong/misconfigured/missing with your setup/environment - that's all I can think of.
Have you tried to locate these files on your computer?
Try passing the -v option to GCC so that you get to see where it is looking for files.

mitrmkar 1,056 Posting Virtuoso

One thing to check, are you absolutely sure that the NodeItem.cpp is included in the compilation?

Have you taken a look at C++ FAQ What does it mean that the "virtual table" is an unresolved external?

mitrmkar 1,056 Posting Virtuoso

I had a similar problem with my program crashing earlier, see http://www.daniweb.com/forums/thread263455.html and i was advised to do this...is it not correct?

Jonsca already pretty much explained your current situation, but I still try to clearly point out what is wrong below ...

Matrix::Matrix(int rows, int cols)
{
// Here you are assigning the member variables mdim_ and ndim_
// to [I]themselves[/I]. It is of no practical use whatsoever.
mdim_ = mdim_;
ndim_ = ndim_;
// So simply delete the above two lines

// What is below is OK. Now you are initializing the Matrix object's
// dimensions in a proper way.
mdim_ = rows;
ndim_ = cols;

In the thread that you linked, the 'this' pointer was used in the constructor to make the code more readable (because the constructor's arguments where named identically to the actual member variables (mdim_ an ndim_), which is confusing).

mitrmkar 1,056 Posting Virtuoso
#include <stdio.h>
#include <stdlib.h>

int main(){

    char option, factor;

    printf("Choose your operator: \"+\" ; \"-\" ; \"*\" ; \"/\" \n>\t");
    scanf(" %c", &option);
    printf("You chose : %c \nChoose your factor:\n>\t", option);
    scanf("%d", &factor);
    printf("You chose : %i\n",factor); 
    printf(" %c", option);
    
    if(option=='+'){
        printf("It's WORKING!");
        system("pause");
    }

    return 0;
}

It looks like the problem would be that factor is of type char , but when you do the scanf(...) , you tell to input an integer (i.e. "%d") instead of char . So, scanf() happily accepts anything that fits into an int , and because an int consumes more memory than a char , you will end up overwriting stack memory - and that changes the value of option .

You might add; printf("option is now [%c]", option); there, so that you see that the value has changed.

So you might remedy this by ..

int main(){

  char option;
  // 'factor' changed to int instead of char ...
  int factor;
  // .. and the rest of the code as is ...

I hope that made some sense. At any rate, you don't want to use mismatched/erroneous format strings with any of the scanf/printf -family functions.

PS. hint: GCC is quite good at pointing out mismatched format strings.

jonsca commented: Another good catch +2
mitrmkar 1,056 Posting Virtuoso

COuld any one help me in solving tis issue?

If you had posted the code using code tags, the code would probably be readable. Now it is not. Perhaps see
What are code tags?.

Salem commented: It's too unreadable for me to even care, even with code tags +19
mitrmkar 1,056 Posting Virtuoso

Just in case you don't know about illegal filenames, see
Filename / Reserved characters and words

So having a filename containing e.g. semicolon(s), would quite likely be a mission impossible.

mitrmkar 1,056 Posting Virtuoso

After the failed attempt to open the file, inFile is in error state. You want to do inFile.clear(); to make it functional again.

mitrmkar 1,056 Posting Virtuoso

I am not able to change anything in the header file, so is there a way to initalize these variables within the .cpp file?

Yes, there is. For example,

Matrix::Matrix(int mdim_, int ndim_)
{
  this->mdim_ = mdim_;
  this->ndim_ = ndim_;

You could/should also change to ..

Matrix::Matrix(int [I]rows[/I], int [I]cols[/I])
{
  mdim_ = rows;
  ndim_ = cols;

That would be more clear, as it is quite confusing when the incoming arguments are named exactly as the member variables.

And furthermore, given a matrix class, sticking to variable names in terms of rows/columns would be more readable (i.e. instead of mdim_/ndim_ and also plain m and n elsewhere in the code).

Note that you have to fix both constructors so that the dimensions are stored properly upon construction.

mitrmkar 1,056 Posting Virtuoso

Can this Static variable be a pointer?

Yes it can. About small tutorials, I'd bet that you'll find reasonable ones by searching the web for example "static member variable in c++".

mitrmkar 1,056 Posting Virtuoso

So can you explain a little bit on Static thing?

Essentially a static member variable (be it of any type) is a variable that is common to all non-static instances of the class.
Maybe the following explains it a bit ..

#include<iostream>
using namespace std;

// forward declaration
class B;

class A
{
  // 'shared_value' is common to all instances
  // of class A because it is 'static'
  static int shared_value;

public:
  A(){}

  void print()
  {
    // Display the current value
    cout << "A::shared_value = " << shared_value << endl;
  }

  // class B is granted access
  friend B;
};

class B
{
public:
  B(){}

  void set(int ii)
  {
    // Modify the A class' private value
    A::shared_value = ii;
  }
};

// Upon program start-up, initialize ..
int A::shared_value = 0;

int main()
{
  A a1;
  B b;

  // The initial value should be 0 ..
  a1.print();

  // Change the A's data through B
  b.set(42);

  // The new value is .. 
  a1.print();

  A a2;

  // a2 shares the value with a1 ..
  a2.print();

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

If the private data is static, i.e. all instances of the class share the static private data, then there is no need for the class object as an argument.

If the private data is non-static, then you must have the class object as an argument because the object instance actually contains the data.

mitrmkar 1,056 Posting Virtuoso

One thing to note, you have had there a simple out-of-bounds write

// 'n + 1' elements -> last valid index is 'n', not n + 1 
  double * coeff = new double[ n + 1 ];

  for(int i= n + 1 ;i>=0;i--)
    // here it would go wrong when i == n + 1 ... 
    cin>>coef[i];
jonsca commented: Good catch. +2
mitrmkar 1,056 Posting Virtuoso

>>so is there anyway of getting around this virtualized registry problem

I don't know a good answer to that one (sorry). I think the User Account Control plays a role in this one too, perhaps try reading Microsoft's documentation on the subject and see what you can make of it.

As to the not yet found key that you've got there, try locating the
HKEY_USERS\<User SID>_Classes\VirtualStore\Machine\Software
key. I bet you'll find it there.

Then again, this is just a Windows feature, that you can 'ignore' i.e. as long as you have sufficient user rights/privileges, you'll be able to write under HKEY_LOCAL_MACHINE and read from there. In other words, at the end of the day, it should not matter to you where the data physically resides in the registry (hope you get the point).

>> or will i just have to live with it?
As a conclusion, since you are on Windows 7, you have to live with it in one way or another...

[EDIT]
If you want to know your account's SID, visit www.sysinternals.com and get yourself an utility called "psgetsid.exe".

mitrmkar 1,056 Posting Virtuoso

I don't want to declare child as pointer. Is this possible to keep it as array instead of pointer?

A bit unclear to me will you be writing C or C++. But anyway, if C++ is allowed, you might store the child nodes in a std::vector, so ..

struct node
{
  std::vector<node> child;
};

the problem is with structure which is very much C

Hmm, a structure is just as much about C as it is about C++, so I suppose no 'admin' would kick you anywhere.

mitrmkar 1,056 Posting Virtuoso

When you have a static non-const member variable, it also needs definition outside the class declaration, so you need to have it like

<snip>
class HotDogStand
{
public:
		void JustSold();
		int Cart;
		int IdNumber;
		int SalesToday;
		int TotalSales;
		int IncrementalSale;
		static int DogCounter;
};

// definition here, outside the class
int HotDogStand::DogCounter = 0;
mitrmkar 1,056 Posting Virtuoso

Another issue: I draw the picture not directly on the Form, but on the Panel. The DoubleBuffering property is protected here :(

You might derive from Panel class and use the derived class as your Panel with DoubleBuffering enabled. Lukezzz was doing the same thing here. Though it seemed that the double-buffering did not help him too much, then again, he has 200 buttons on that derived Panel (which is a lot of buttons) and your situation might be very different.

mitrmkar 1,056 Posting Virtuoso

No. The program didn't like that constructor for some reason.
Success!

Wow, this is getting actually quite entertaining :)

Sorry AD, but you made a radical change there. That is, now there is an object instantiated in the usual way, i.e. "WCS m(L"Hello");", i.e the code is pretty much guaranteed to work.

But the original problem arose due to the way the constructor was used and the attempt to reference the (more or less) temporary object.

[EDIT]
@CppBuilder
GCC docs state one aspect with regard to the temporary objects and their lifetime, I think it's quite relevant here, since you mentioned referencing member variables, so maybe check out Temporaries May Vanish Before You Expect.

mitrmkar 1,056 Posting Virtuoso

no, see this

What's there is not quite same thing that you are doing in this thread (very close though).

However, you are not referencing the object that gets constructed, but rather its member variable. The object really gets destructed before the output.

So, to keep the object around long enough to see the output, it would be:

WCS const & ws = WCS(wstr);
wcout << ws.string;

And there is a little too-small-a-buffer hitch ...

wcscpy_s(c, wstr.size() + 1, wstr.c_str());

[EDIT]
A good string-catch by AD, so the above .string really should be something else that it is. But you get the point I think.

mitrmkar 1,056 Posting Virtuoso

why does this program have an exception in VC++ 2008 Express?
I tested it in a borland compiler & there was no exception.

VC probably destructs the object as soon as the reference has been set i.e. before any output.

Just out of curiosity, when you run the program under borland, does the destructor get called before the "wcout << c"?

mitrmkar 1,056 Posting Virtuoso

The error is quite obvious

char *compareFN=NULL;
// 'compareFN' is a null pointer, strcpy() is guaranteed to fail
strcpy(compareFN, ((*myPtr).second)-> getEmpFirstName());

So strcpy() copies the source buffer to the destination buffer, which you don't have. In other words, you must have a char buffer sufficiently large to hold the incoming data + the terminating null character ('\0'). Perhaps see strcpy().

[EDIT]
Beaten by IsharaComix, providing a good suggestion, though I still suggest that you check out the strcpy().

mitrmkar 1,056 Posting Virtuoso
int main()
{
    Matrix A(2, 3);
    Matrix B(3);

    return 0;
}

>> Then does this create 2 separate matrices stored in data_?
Yes it does. You have two distinct objects of type Matrix, they both withhold their own vector, so there is no interference between the two objects.

If you'd have a static vector there, then each instance of a Matrix would operate on the very same vector, so

class Matrix {
 public:
 <snip>

 private:
  static std::vector<double> data_; // Vector storing the matrix data
};

Then you'd be better of passing in the Matrix objects by reference and even by const reference, just to avoid temporary Matrix from being created upon method calls, so rather

// if 'b' is not supposed to change -> make it const
// and pass it in by reference, to be more efficient
void Subtract(const Matrix & b);
mitrmkar 1,056 Posting Virtuoso
// First you have to do this
for(for_loop_conditions)
{
   free(charArray[i]);
}

// ... and then also this
free(charArray);

So there has to be a matching free() for each malloc() that you do.

PS. Just to be clear ... if charArray is also dynamically allocated, it needs to be declared as: char ** charArray i.e. not char *charArray .

mitrmkar 1,056 Posting Virtuoso

Adding a note ... you are doing some out-of-bounds access there, for example

// two 'coord' objects, meaning
// that you only can access indexes 0 and 1, nothing else.
coord asteroid[2];
...
//Collision check
for(int i = 0; i< 2; i++)
{
  asteroid[i].collision(asteroid[i+1]);
}
mitrmkar 1,056 Posting Virtuoso

I have done the same in Java

http://www.technicalypto.com/2010/02/stack-using-linked-lists-in-java.html

Good for you, but please don't resurrect an old C++ thread just for the sake of saying that you've done something similar in Java, thank you.

mitrmkar 1,056 Posting Virtuoso

Actually, for all the *_s functions -- stop using them.

I would rephrase that a little

Actually, for all the *_s functions -- stop using them if you aim to write standards-compliant code. Otherwise, learn and use them (these functions exist for a good reason). Just be aware that these functions are available only with recent Microsoft's compilers.

mitrmkar 1,056 Posting Virtuoso

I think you are just 'moving too fast'. Study the documentation, for example fopen_s().

mitrmkar 1,056 Posting Virtuoso

can u give me the codes... :(

This assignment has been discussed before

Salem commented: OMG, it's contagious! +19
mitrmkar 1,056 Posting Virtuoso

how do you create one ?

Im trying to sort objects by their z

You might have something as simple as

// Compares two game objects by 'z'
bool game_obj_compare(const game_obj * lhs, const game_obj * rhs)
{
  return lhs->z < rhs->z;
}

// To sort a vector of game_obj pointers ...
std::sort(v.begin(), v.end(), game_obj_compare);

Since the vector stores pointers, you cannot use the

std::sort(v.begin(), v.end());

version, which uses the overloaded operator < .

mitrmkar 1,056 Posting Virtuoso

Something is wrong with "dear_son"

Yes, you do have room there for 5 children

dear_son = gcnew array<my_child^>(5);

but they need also be given birth first, so

F.dear_son[0] = gcnew my_child;
F.dear_son[0]->mas_1D[1] = 23;

So there were no objects yet, only handles to such, hence
>> not set to an instance of an object

mitrmkar 1,056 Posting Virtuoso

OK, then try to figure out how to pass the switches to the compiler. I don't have Dev-C++, but generally these options are found via something like;
Project / Settings / Compiler / Compiler Options. Can you find anything similar in Dev-C++?

Here is a link to the GCC Options to Request or Suppress Warnings
As you can see, there are quite a lot of them, the link is to gcc v.3.3.6 online docs (that might be close to the version that you have). At the very minimum, you want to pass the -Wall option to the compiler (enables all warnings).

[EDIT]
You can find out your compiler version by issueing gcc --version in a command prompt.

mitrmkar 1,056 Posting Virtuoso

>> Why is it creating the empty file?
I'd suggest debugging the program and try to see where it fails and why.

You could use
_stat() to check both the file's existence and its size in one go.

mitrmkar 1,056 Posting Virtuoso

>> I've looked around in my code, and I can't find any variables that have been assigned that address(0xccccccd0).

In MS VS debug builds, if you don't explicitly initialize a pointer that is on the stack, it gets initialized with the value 0xcccccccc. So make sure you don't use uninitialized pointers and watch out for pointers having the value 0xcccccccc rather than 0xccccccd0.

0xccccccd0 is rather a side-effect of the root cause (access through uninitialized pointer) i.e. most likely you won't be finding pointers with that value.

Salem commented: Nice +19
mitrmkar 1,056 Posting Virtuoso

Maybe study the sprintf() reference.

Nick Evan commented: What's this word "study" ? ;) +12
mitrmkar 1,056 Posting Virtuoso

i am facing problems of destructor in the following code.destructor is not working

The memory allocation is one byte off, you need to allocate an additional byte for the null terminator placed there by strcpy() , so

len = strlen(str) + 1;

FYI, sizeof(char) is always one (1), so you can drop sizeof(char) altogether.

In the constructor, len is rather 1 than 0, though this does not affect the program as of now.

Then last but not least, it's a good practice to check whether the memory re/allocation succeeds. If they don't, the program crashes.

[EDIT]
Since this is C++, maybe rewrite the program using new/delete or std::string .

mitrmkar 1,056 Posting Virtuoso

so is this method convenient for long time pauses like 2-3 days?
because tstart needs to be large number?

In terms of being sufficient, the time_t data type is OK. Check out how many bits your time_t actually is, (probably 64).

Then again, this is the same construct that you already tried and you stated; "man this works BUT IT USES 100 CPU", so will it be convenient to use ~100% CPU for a couple of days?

mitrmkar 1,056 Posting Virtuoso

I tried to move the entire visio contents:
/VC/bin/
to the same folder

I suppose you mean Visual Studio instead of 'visio', right?

Anyway, consider that upon install, the VS tools do modify the system by modifying environment variables (and being MS tools, maybe system registry etc.) in order to locate things at run-time. So, moving the tools might not be a good idea in the first place.

Then again, Visual Studio comes with a batch file vcvarsall.bat, which configures the environment (via other .bats) so that the binaries find what's needed. So maybe locate this vcvarsall.bat, which is usually in the VS root install dir, and see what you can do in terms of re-configuring the paths and such. It may even work.