mitrmkar 1,056 Posting Virtuoso

>> the compiler is about a year or 2 old.
>> Its a C++/C compiler. gcc

Most likely the code is not a compiled as C, but C++ instead. In C, you don't need to cast return value from malloc(), and moreover, you shouldn't do that.

sree_ec commented: nice link +1
mitrmkar 1,056 Posting Virtuoso

I think kes166 pointed out your problems.

I'd just suggest that when you compile your programs, pass the following switches to the compiler (via Dev-C++ IDE) -Wall -Wextra -pedantic That will enable most of the warnings and generally also warns about (some) non-standard code (like variable length arrays, which you are using).

Also, why not switch from Dev-C++ to say Code::Blocks, which comes with probably ~5 years more recent compiler (and IDE too).

mitrmkar 1,056 Posting Virtuoso

Since this is MFC, see CComboBox::AddString() GetDlgItem() returns a CWnd * , meaning that you need a typecast to CComboBox * .

For example

CComboBox * pCombo = (CComboBox *) GetDlgItem(IDC_COMBO1);
pCombo->AddString("Text");
fire_ commented: Thank you. It worked +1
mitrmkar 1,056 Posting Virtuoso

perror() might come in handy, so perhaps try

void uloz2D(char nazevsouboru[])
{
    // You don't need the NAZEVPR2 variable here

    printf("%s\n", nazevsouboru);

    FILE *soubor2 = fopen(nazevsouboru, "w");
    if(soubor2)
    {
        fprintf(soubor2,"A");
        fclose(soubor2);
    }
    else
    {
        // Failed, what's the reason?
        perror(nazevsouboru);
    }
}

Are you sure about your last argument to GetWindowText() , that is the count of characters that fit in the input buffer. In other words,

char retezec[32] = "";
     GetWindowText(GetDlgItem(hwnd, IDB_TEXTBOX1), retezec, sizeof(retezec));

or maybe

TCHAR retezec[32] = _T("");
     GetWindowText(GetDlgItem(hwnd, IDB_TEXTBOX1), retezec, sizeof(retezec)/sizeof(*retezec));
mitrmkar 1,056 Posting Virtuoso

I compiled using GCC v4.5.1

I'm having hard time in believing that 4.5.1 would come with the pre-standard file <iostream.h>. Are you sure that your compiler/IDE configurations are OK?

Would be nice to know if Visual Studio 2010 also behaves like this, anyone care to test?

mitrmkar 1,056 Posting Virtuoso

>> Your answer would require to include an additional header file <cstdlib>
My test works fine without this header.

The only header I have to include is iostream.h for 'cout'

Your compiler is not standards-compliant then, exit() needs the <cstdlib> header. Maybe try out a modern compiler and see if your old code compiles?

mitrmkar 1,056 Posting Virtuoso

>> i find answer
Your answer would require to include an additional header file <cstdlib>, and you cannot do that, given that you only are allowed to modify the function() function.
I think that the general problem setup suggests something else.

>> then i will tell you that answer
By all means, post back with the answer when you have it.

>> then you will sorry from me
I don't quite understand what that means .. though you sort of sound as having been insulted, if so, how come?

mitrmkar 1,056 Posting Virtuoso

Ok ... I'll admit, I'm lost. I used #defines to declare token strings. I'm not seeing how that will do anything?

You #define d wrong things then :)

How about us letting this thread get some rest and see if the OP returns?

VernonDozier commented: +rep for figuring out the #define. +11
mitrmkar 1,056 Posting Virtuoso

>> This very much looks like a 'trick' question of some sorts.

Good lord, I see what you mean.. If the teacher actually gave this assigment (s)he should be fired for encouraging this abomination of a code...

--- wait --- see my above post about the possible good outcomes of this problem .. let's not fire the teacher yet, right? ;)

Nick Evan commented: Hmmm.. I'm still not convinced, but I see your point :) +15
mitrmkar 1,056 Posting Virtuoso

Hunh????? :-O :-/ :confused:

In this case, let's just put aside the non-standard code presented by the OP plus the seemingly 'impossible' basic requirements. It's quite obvious that the "void main()" etc. is not the key topic here, at least from the OP's viewpoint.

Again, like I wrote above, a simple #define solves this 'problem' in 100% standard and portable C++ code. As far as I can see, the only good outcome of this exercise for the OP would be to realize the possible dangers of using macros (e.g. using #defines carelessly).


@OP
It would actually be nice to know how come you are facing this dilemma, would you care to share that with us?

mitrmkar 1,056 Posting Virtuoso

This very much looks like a 'trick' question of some sorts. So assuming that the requirements are that 1) the output must be zero (0) and 2) only the comment block is to be modified .. it can be done in standard C++, here's a hint, replace

void function(int arg)
{
char chars[10];
/*
some statments
*/
}

with

void function(int arg)
{
char chars[10];
#define <something here>
}

So, "<something here>" needs to be replaced with something.

mitrmkar 1,056 Posting Virtuoso

>> ...When i try to get that date back again in the Actor class
>> by the code inception = dateInception.getCharacteristics();
>> I get a result that is like 123441234/1234234234/1234234.

By looking at the code (your first post), this line you mention, only exists within the Actor's constructor, meaning that it returns the newly constructed dateInception 's data - do you have false expectations here? Date::getCharacteristics() does not work as you have intended ..

Change

string Date::getCharacteristics()
{
    ...

    out >> dateString;

to

string Date::getCharacteristics()
{
    ...

    // Stuff the stringstream content into the string
    dateString = out.str();

    return dateString;
}

or maybe drop dateString altogether and simply

string Date::getCharacteristics()
{
    ...

    // Return the string
    return out.str();
}

[EDIT]
Just noticed that Actor::getCharacteristics() also has similar faulty usage of stringstream.

mitrmkar 1,056 Posting Virtuoso

>> dude, i'm creating win32 console application......

Ancient Dragon's suggestion will work provided that you #include <windows.h> If you don't want to pull in the windows.h header, a more lightweight solution would be to use C run-time function _chmod(). To use that function, you need to #include <io.h> .

mitrmkar 1,056 Posting Virtuoso

When you write to the file, sizeof(m_data) gives sizeof(deque<double>) . Instead you need sizeof(double) .

Jsplinter commented: that fixed it! +1
mitrmkar 1,056 Posting Virtuoso

>> This compiles, but it is not working.

The loop condition is backwards (has ! ).
You are complicating the reading, to read a double at a time ..

ifstream myfileIN("data2.bin", ios_base::binary);
double dub;
// As long as sizeof(double) bytes is read ..
while(myfileIN.read(reinterpret_cast<char*>(&dub), sizeof(dub)).gcount() == sizeof(dub))
{
  dq.push_back(dub);
}

PS. If you'll be using strtod() , the buffer must be '\0'-terminated, like nbaztec noted.

mitrmkar 1,056 Posting Virtuoso

A suggestion, you might use stringstream for extracting the two fields, that would work for both TAB and SPACE -separated fields.
That would be along the lines of ..

#include <sstream> // for stringstream

// Function to perform lookup in provided MAC to hostname file
string search_eaddr(const string & search, const string & hostfile)
{
  ifstream in(hostfile.c_str());

  if(!in)
  {
    // Error, do something here ...
  }

  string line;
  while (getline(in,line))
  {
    // Stuff the line into the stream
    stringstream ss(line);
    string mac, host;

    // Extract, note that any trailing whitespace will NOT end up in 'host'
    if(ss >> mac >> host)
    {
      if(mac == search)
        return host;
    }
  }
  return "";    // If no match found, will return an empty string
}

Then a couple of things .. this

if (argc < 2 || argc > 3)    // Checks the number of arguments entered by user
{
  // If too many or too few arguments provided, program usage will be displayed.
  printf("\n    Usage: %s <dump_filename> (host_filename) \n\n", argv[0]);
  return 1;
}
if (argc == 3) // Checks if MAC to hostname file provided
{
   ...

could be simplified to

// Checks the number of arguments entered by user
if(argc != 3)
{
  // complain here and return 
  return 1;
}

Then instead of

input2 = fopen(argv[2], "r");    // Verifies that MAC to hostname file exists and can be opened.
if(fopen == NULL)
{
  printf("Cannot open host list\n");
  return 1;
}

you definitely want to have

…
mitrmkar 1,056 Posting Virtuoso

>> I go menu->settings->build settings->select gnu-g++ in the left tree->switch->
>> and change the -l to the -lmapi32

Those are general build settings, shouldn't you rather add the mapi32 library to the current project's configuration? That would be; from the menu, select Workspace / Open active project settings / Linker, then enter mapi32 in the Libraries: field.

That should do it, assuming that you have libmapi32.a in the lib directory.

mitrmkar 1,056 Posting Virtuoso

From the VS 6 Help menu, select Keyboard Map and then Edit instead of 'bound commands',
that'll display the commands/bindings you want.

mitrmkar 1,056 Posting Virtuoso

>> Does anyone know the event that causes the carriage return animation to play?

I believe you've coined a new term for a thing which is more commonly known as a caret. Perhaps read up about Carets and see if it's possible to achieve what you want.

mitrmkar 1,056 Posting Virtuoso

Since you are using the same ifstream object throughout the do/while -loop, you need to call tempsynth.clear() whenever .open() fails. Otherwise the object remains in fail state and makes no attempt to open any further files.

By the way, are you initializing the random number generator (i.e. calling srand() )?.

mitrmkar 1,056 Posting Virtuoso

>> 'book_list' : undeclared identifier

In Main.cpp line #26, the missing variable has been commented out, so you need to remove
the comments to have the book_list declared.

...
// Declare the book list and an STL linked list variable
list <BookRecord> book_list;
...

On a side note, does your instructor consider the following a good/safe practice?

...
char option[3];

// Get some input, hoping that the input will fit into 'option' 
// without an out-of-bounds write.
cin >> option;
BobbieJean commented: mitrmkar's respnse to my post was the one that solved it! Thanks a bunch mitrmkar!!! +1
mitrmkar 1,056 Posting Virtuoso

Would it be possible to provide a compilable example program only including the few (?) necessary classes?

Have you tried this code with other compilers?

mitrmkar 1,056 Posting Virtuoso

Perhaps rather try _CrtCheckMemory() to narrow down the problematic part(s).
I.e. in the simplest form of its usage, your code might look like ..

#include <crtdbg.h>
...
// Is the memory still good?
_CrtCheckMemory();
populateMatrix(data, g, Ex);
// Is the memory still good?
_CrtCheckMemory();
stats m(data);
// Is the memory still good?
_CrtCheckMemory();
m.getStatistics();
// Is the memory still good?
_CrtCheckMemory();
...

Run your (Debug build) program in the debugger, when _CrtCheckMemory() detects corruption, by default it displays an Assertion Failure message box of some sort - at that point, hopefully you'll be enlightened.

mitrmkar 1,056 Posting Virtuoso

At least the stats constructor needs some attention, see the comments below.

<snip>

while(i<(d_data->nCols*d_data->nRows)){
  d_data->data[i]=datap->data[i]; 

  // 'i' gets incremented too early here
  i++;	

  // Upon last iteration; i == d_data->nCols*d_data->nRows, which is wrong

  uchar n = datap->data[i];

  // .. then, the damage is done here ...
  d_data->data[i]=n;

  uchar m = d_data->data[i];			 
}
mitrmkar 1,056 Posting Virtuoso

I trying to get the LAST modified

Then you want to use ftLastWriteTime .

to decide which text file is the most recent

You can directly compare the FILETIMEs using CompareFileTime()

iamthwee commented: ty +11
mitrmkar 1,056 Posting Virtuoso

In function ‘bool operator<(const Student&, const Student&)’:
../src/Student.cpp:25: error: passing ‘const Student’ as ‘this’ argument of ‘int Student::getscore()’ discards qualifiers

Your compiler is trying to tell you that you want to declare the getscore() and getname() methods as const .
So, instead of stripping away constness, you might rather add some more, like so ..

class Student {
...
  string getname() const;
  int getscore() const;
  friend bool operator <(const Student&, const Student&);
...
};
// and
...
string Student::getname() const {return name;}
int Student::getscore() const {return score;}
...

Then again, since the operator < overload is a friend, you can write it without calling the member methods at all ..

bool operator< (const Student& first, const Student& second){
  // Directly access the member variables ..
  return (first.score < second.score);
}

I.e. in this case, you actually could do without declaring the getxxxx() methods const, but I'd suggest that you declare them as const - regardless of how you write the operator < overload.

In main(), you are using GCC's variable length array extension (Student input), it is not standard C++ and you could very easily do without it..

int main()
{
  // size is not a global variable anymore
  int size;
  cout << "How many students do you want to enter?" << endl;
  cin >> size;
  //// Non-standard array not used at all
  //// Student input[size];
  // This gives you a properly sized vector ..
  vector<Student> roster(size);
  
  string _name;
  int _score;

  for(int i=0;i<size;i++){
    cout …
mitrmkar 1,056 Posting Virtuoso

Your ifstream is in a fail state once you have exited the loop.
To make the stream functional again, use clear(), like so..

// Clear out any error state bits
in.clear();
// Now seekg() will work
in.seekg(0, ios_base::beg);

Then, don't use .eof() in a loop control, it will end up biting you.
There are many discussions at DaniWeb and elsewhere about why it is bad.

Instead, you could read from the file as follows ..

// Loop while reading of two values succeeds ..
  while(in >> code >> amount)
  {
    if (amount > N)
        records++;
  }

  // Was the whole file read?
  if(in.eof() == false)
  {
    // No, do something ...
  }

To understand this better, modify your input file so that it contains non-numeric data and watch how your current program enters an infinite loop, for example:

1213 2232
4324 gotcha
432 34233

vanalex commented: very helpful and clear +3
jonsca commented: good one +4
mitrmkar 1,056 Posting Virtuoso

Remove the #include "newmenu.rc" from the source file. It is only to be included via the Solution/Project that you have - i.e. that file should display in the Solution Explorer. To add the file to the solution, use Project / Add Existing Item and pick the .rc file - that should suffice.

PS. You might search the web for free resource editors.

mitrmkar 1,056 Posting Virtuoso

I think the Problem is more of C++ than it is an OpenCV one.

Looking at the code you've posted, you have huge problems with memory overruns, and forgetting to delete the allocated memory (which may be hiding these overruns).

One option would be to use vector<float> for all of your arrays. That way, the memory is managed automatically, plus you'll be alerted to out-of-bounds read/writes at the moment they occur.

Try the following program and see what happens

#include <iostream>
#include <vector>

int main()
{
  using namespace std;

  int filterHalfWidth = 3;
  vector<float> gx_v(filterHalfWidth, 0.0f);

  try 
  {
    // Note:
    // This is exactly the same loop construct that you are using
    //
    for (int i = -filterHalfWidth; i <= filterHalfWidth; ++i)
    {
      cout << "accessing index: " << filterHalfWidth+i;

      // Use .at() rather than [], because it gives you
      // an out_of_range C++ exception on illegal access ..
      gx_v.at(filterHalfWidth+i) = i;

      // Doing good
      cout << "-> OK" << endl;
    }
  }
  catch(out_of_range & e)
  {
    // .. which you can then catch
    cout << "-> FAIL" << endl << "exception: " << e.what() << endl;
  }

  // Done, the memory reserved by the vector will be 
  // automatically released in a moment or two ..

  return 0;
}
mitrmkar 1,056 Posting Virtuoso

A very basic C++ tutorial that you might check out -> http://www.learncpp.com/

mitrmkar 1,056 Posting Virtuoso

Gives this error
undefined reference to `operator<<(std::basic_ostream<char, std::char_traits<char> >&, Complex const&)'

This occurs because the Complex & is const - and you try to use non-const methods on the Complex object.
By making the methods const , your current code will work, like so ..

class Complex{
...
  int getRe() const {
...
  int getIm() const {
...
  friend ostream & operator << (ostream &, const Complex &);
};

Furthermore, since the operator overload is friend, you can directly access the member variables (no need to call the methods), like so ..

os << "re:" << it.re << " im:" << it.im << "| " << endl;

Regarding usage of const , I'd suggest that you read about const correctness.

Alex_ commented: Thank you very much! +2
mitrmkar 1,056 Posting Virtuoso

Try to implement the following

class Complex
{
...
  // friend - allows access to private members
  friend ostream & operator << (ostream &, const Complex &);
...
};
mitrmkar 1,056 Posting Virtuoso

The compiler sees that line as a declaration of a function ( t2 ) which takes no arguments and returns an object of class test .

mitrmkar 1,056 Posting Virtuoso

I don't understand why to have a line break after the 26th letter ...

You need to use 27 because you increment the counter before the if-statement.

mitrmkar 1,056 Posting Virtuoso

Currently, LOAD GAME appears and immediately goes into the game without any "wait(n)" intervals.

Why won't it work?

Well, you initialize int countdown = 5 , so that will cause it to bypass the for-loop altogether.

PS. I recently saw;
"When C++ is your hammer, everything starts to look like a thumb."

mitrmkar 1,056 Posting Virtuoso

Only considering the formatting of the code,
consider a more readable alternative ..

#include<iostream>
using namespace std;

int main()
{
  char letter;
  int counter = 0; //set the counter to 0

  for (letter = 65; letter <= 122; letter++)
  {
    if(   (letter == 91)
      ||  (letter == 92)
      ||  (letter == 93)
      ||  (letter == 94)
      ||  (letter == 95)
      ||  (letter == 96)
    )
      continue;

    counter++; //increment the counter in the loop
    
    if (counter == 27) //counter condition
      cout << " \n";

    cout << letter << " ";
  }

  counter = 0; //reset the counter

  return 0;
}
mitrmkar 1,056 Posting Virtuoso

@OP
Just a thought, this missing '}' might be due to namespace usage, so

// Begin the namespace
namespace my_namespace {

// code here

} // <- namespace must end with a '}'
mitrmkar 1,056 Posting Virtuoso

Looks like your header file is lacking a '}', the sortWaterNetwork.cpp seems to be OK.

[EDIT]
@Fbody
I think you missed that the OP mentioned "error list excluding the error for other header since the errors are the same", hence #49.

mitrmkar 1,056 Posting Virtuoso

I think you have an issue with precompiled headers.
In the noduri.cpp file, switch the order of your #includes to be

#include "stdafx.h"  // <- first the precompiled header
#include "noduri.h"  // then other includes follow
...

The above Wikipedia link briefly explains your issue, MSDN documents it more thoroughly - it can be rather complicated actually. You may want to turn the precompiled headers option off altogether.

Scu commented: Great help. +1
mitrmkar 1,056 Posting Virtuoso

Actually, those are from the same project. The only difference is that I modified temporarlly <list> with <lists> to see if it gives error

OK, as far as I understand, then the above error message listing is not a match for the code that you posted.
If that's the case, then please re-compile and re-post the actual errors.

[EDIT]
In the header file you have commented out using namespace std; and in at least two of the method declarations you are using list .

Those you can fix by ..

void CautaElementeTip(char *tip, std::list<clsElemente>& elemente);
mitrmkar 1,056 Posting Virtuoso

I guess it all strats from this C2653 error which speads through all my new header files.

The first error that occurs is:

Error	3	error C1083: Cannot open include file: 'lists': No such file or directory	i:\sync\sortwaternetwork\sortwaternetwork\noduri.h

However, that does not match the noduri.h/#include <list> that you posted - which somewhat implies that you might be working on one set of files but compiling another set of files.

mitrmkar 1,056 Posting Virtuoso

Because I've not seen that difference documented in wikipedia here
Maybe I looked not in that direction or do we need to modify wiki, huh ? :)

That Wikipedia page links to Incompatibilities Between
ISO C and ISO C++
where this is explained, see the section "Empty parameter lists".

mitrmkar 1,056 Posting Virtuoso

I believe your 'username' pointers ( nom_usuario ) end up pointing to the same index of the one and only buffer you are using (i.e. buffer indirectly via buffer2 ).

Try changing the code to malloc() + strcpy() the username data instead, like so..

int insertar(char* buffer2, struct lista* maestra,int count, char* IP)
{
  if(count == 1) //This only applies if the list is empty
  {
    /* Note: sizeof(*nodo1) instead of '50' */
    struct nodo *nodo1 = malloc(sizeof(*nodo1));
    nodo1->IP.sin_addr.s_addr=inet_addr(IP);
    
    /* Note: 1 extra byte for '\0' */
    nodo1->nom_usuario = malloc(1 + strlen(buffer2));
    strcpy(nodo1->nom_usuario, buffer2);

    /* .. remember to free() the memory when done with it */

    nodo1->siguiente=NULL;
    maestra->primero=nodo1;
    maestra->ultimo=nodo1;
...

Does that make a difference?

[EDIT]
Also note that malloc() can return a NULL pointer! So you might make sure that it does not happen.

PS. Naturally this approach applies throughout the program (i.e., every nom_usuario is to be handled this way).

mitrmkar 1,056 Posting Virtuoso

>> My C++ is rather old but this should work.
Sorry but that will not work either. Consider compiling the code that you post. Even if you are posting minimal snippets/one-liners.

mitrmkar 1,056 Posting Virtuoso

About Malloc
Malloc() is ...

It is malloc (not Malloc).

References

No references guyz ... Only one my "brain" .. LOL..

You can find the current draft standard here ..
http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf

mitrmkar 1,056 Posting Virtuoso

You might post the current code and point out the current problems.

mitrmkar 1,056 Posting Virtuoso

To restate, since it took me a while to figure out exactly what you meant, take out the semi-colon at the end of your loop definition.

Note that there is also an unfortunate comma inside the original loop.

mitrmkar, please be a little more explicit next time. Noticing one minor character change can be difficult to spot without pointing out the change.

The OP is welcome to ask more questions, if needed (i.e. there was something left to be figured out). Though you may be right that in this case it might have been better to point things clearly out (only the OP knows).

mitrmkar 1,056 Posting Virtuoso

Your for-loop is wrong ..

void getRaise(double pay[], int size)
{
// should rather be ..
for(int x=0; x <size; ++x)
...
Salem commented: Nice catch +20
iamthwee commented: It was obvious to me! +11
mitrmkar 1,056 Posting Virtuoso

All the time, at least in the C and C++ forums.

mitrmkar 1,056 Posting Virtuoso

but the final output comes out in the form of an infinite loop

Adding one thing...
you are writing to a file named "emp.dat" and then trying to open "emp.txt", which presumably does not exist (?). The bad usage of .eof() does not protect you from this. You can use .is_open() for checking whether a file was opened or not.
So, get rid of the .eof() there and read properly from the file the way Ancient Dragon showed. Naturally, pay attention to other suggestions too ;)