mitrmkar 1,056 Posting Virtuoso

Inside the class declaration is a typo, change to ..

template<class T3, class T4> friend std::ostream & operator<<(std::ostream& os, const TwoThings<T3, T4> &);

And then the definition without the scope resolution operator

template<class T3, class T4> std::ostream & operator<<(std::ostream & os, const TwoThings<T3, T4> & tt)
{
    std::cout<<tt.thing1<<' '<<tt.thing2;
    return os;
}

When in doubt, a good place to get a 'second opinion' about a given piece of code is the Comeau's Test Drive Comeau C++ Online. It is supposed to be a very standards-compliant compiler and tends to produce quite understandable error messages.

mitrmkar 1,056 Posting Virtuoso

Yes, the program crashes

By looking at the initial code you had and the code that crashes, I'm guessing that something like the following happens ..

struct test
{
  const char * peek(bool return_pointer_to_char)
  {
    if(return_pointer_to_char == true) {
      // return a valid char *
      return "testing";
    }

    // No return value specified in this case,
    // program's behaviour is pretty unpredictable
  }
};

int main()
{
  test t;

  // This cout will work
  cout << t.peek(true) << endl;

  // But this one will not, you are likely to
  // see a crash of some sort
  cout << t.peek(false) << endl;

  return 0;
}

So, you have to make sure that anytime a function that is declared to return something, it really returns a valid value.

>> But may I ask, what's that int i that he declared? what's it for?
The int i was used for receiving the integer values read from the file. You might try out those programs with the input files demonstrated, to see how they actually work and moreover, to see how the usage of eof() is bad.

mitrmkar 1,056 Posting Virtuoso

>> please tell me if there are any bugs in this program
Hmm, maybe read When asking about code.

mitrmkar 1,056 Posting Virtuoso

Have you considered using STL containers instead? Such as vector<ICOMInterface*> or list<ICOMInterface*> for example.

mitrmkar 1,056 Posting Virtuoso

Here's a version with some assert() added. Run it in the debugger and you'll probably be spotting errors quite quickly.

#include <cassert>

void Array::merge (int first, int last)
{
  const int arr_size = last-first+1;

  int* merged = new int[arr_size];
  int mid = (first + last) / 2;
  int secList = mid + 1; // beginning of second list
  int firstList = first; //beginning of first list
  int j = first; // used for array index assignment

  while ( (firstList <= mid) && (secList <= last) )// both lists #1 & #2 are not exhausted
  {
      if (data[firstList] < data[secList])// data in list #1 < data in list #2
      {
          // check j ...
          assert(j < arr_size);
          merged[j] = data[firstList];// <- data in list #1
          firstList++;
      }   
      else
      {
          // check j ...
          assert(j < arr_size);
          merged[j] = data[secList]; // <- data in list #2
          secList++;
      }
      j++;
  } // end while
    
  if (firstList > mid)
  {
      for (int q = secList; q <= last; q++){
          // check j ...
          assert(j < arr_size);
          merged[j] = data[q];
          j++;
      }
  }
  else
  {
      for (int r = firstList; r <= mid; r++)
      {
        // check j ...
        assert(j < arr_size);
        merged[j] = data[r];
        j++;
      }
  }

  for (int i = first; i <= last; i++)
  {
      data[i] = merged[i];// overwrite original positions with "merged"
  }

   delete [ ] merged; //commented out due to segmentation fault
   merged = NULL;
}

I'd suggest you to check all your code for out-of-bound writes.

mitrmkar 1,056 Posting Virtuoso

How would I make a change to a year or something in this vector

See vector::operator[]. At the bottom of that page are links to other vector accessors. Also you might use iterators, also explained there.

>> and print it for the user??
You are doing it already ..

std::cout << CarVector[i].getMake() << std::endl;
mitrmkar 1,056 Posting Virtuoso

Yay I was already able to solve this

Nice.

>> whenever Stack s becomes empty, the program terminates
You mean 'terminates' as in; the program crashes? If so, what is the error message?

Note that using eof() like you do, generally is not a good idea. Dave Sinkula tells you why here.

mitrmkar 1,056 Posting Virtuoso

char text[10]

You need to increase the size of that array by one, if you intend to copy a literal such as "0x00000000" into it (you must account for the terminating '\0' character). Otherwise, you'll be writing out of bounds, which is not allowed.

PS. Maybe consider using std::string s instead of char arrays.

jonsca commented: Good catch +3
mitrmkar 1,056 Posting Virtuoso

... load and display images. After using the program for a while loading and displaying images then all of a sudden all the windows on the desktop disappear including the task bar on the bottom...

This sounds very much like you are leaking GDI objects. That is, you are not disposing of the Windows' GDI objects you create/allocate. One handy utility to check this would be GDIView, which enables you to pinpoint the types of the objects you might be leaking.

Of course, also pay attention to malloc()/free() as already noted.

mitrmkar 1,056 Posting Virtuoso

I declared it as

char word[15];

my problem is that run time error. i can't get rid of it :(

Perhaps you could tell us what this run time error actually is?
Moreover, have you been getting several different types of run time errors, and if so, which ones?

Maybe also tell which compiler you are using.

mitrmkar 1,056 Posting Virtuoso

If I use OnCtrlColour handler, when is the function called..? Is it everytime the the dialog is reload/refresh or is it continuously called independent of what I do..?

MSDN says;
"The framework calls this member function when a child control is about to be drawn." In practice, this means that it gets called very frequently.

>> How do i pass the required parameters (CDC* pDC, CWnd* pWnd, UINT nCtlColor) to the function..?
You don't need to do anything about that, MFC handles the parameters for you automatically.

The nCtlColor parameters specifies what kind of control needs to painted, so if you want to paint edit controls only, then ..

HBRUSH CZilchDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
  HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

  // Are we painting an edit control?
  if(nCtlColor == CTLCOLOR_EDIT)
  {
    // Yes ...
    // Set the text color to red
    pDC->SetTextColor(RGB(255, 0, 0));
    ...
  }

  return hbr;
}
mitrmkar 1,056 Posting Virtuoso

Then sscanf separte the first and second putting on p1 and p2 char, the
rest is ignored.

GCC (hint) disagrees with you ..

warning: [I]too few arguments[/I] for format

To ignore the rest, you might use ..

sscanf(data, "%[^':']:%[^':']:%*s", p1, p2);
mitrmkar 1,056 Posting Virtuoso

I have actually declared "word" as char in my actual program.. I just forgot to include it here...

So are you saying that you have declared ..

char word;

i.e. NOT ..

char word[some size here];

?

PS. You still 'forgot' to include it.

mitrmkar 1,056 Posting Virtuoso
Oldproc = (PROC)SetWindowLong(Childs[1], GWL_WNDPROC, (DWORD)EditProc);

You might want to check that SetWindowLong() actually succeeds. And while you are at it, you might switch to SetWindowLongPtr() altogether (it supersedes the former).

mitrmkar 1,056 Posting Virtuoso

where this is coming from?

The runtime code calls abort() (or perhaps even your own code?).

Which compiler/IDE/OS you are using?

mitrmkar 1,056 Posting Virtuoso

Thanks... I changed it to this, but it still is not reading the if statements

You are using uninitialized variables local to the functions, consider the following ...

void decline ()
{
  char letter,  // <- A local variable, uninitialized
       status;  // <- A local variable, uninitialized

  // See what values these variables have at this point ...
  std::cout << "letter's value is [" << letter << "]" << std::endl;
  std::cout << "status's value is [" << status << "]" << std::endl;

  std::cout << "About to enter if-statements with those values ..";

  if (letter == 'D' || letter == 'd' && status == 'X' || status == 'x')
  {
...
}

Add those extra lines there and see what the output is. Apparently you need to figure out how to pass the needed information to the functions.

mitrmkar 1,056 Posting Virtuoso

-the new project is now running so I choose File, New, File and then choose C++File in the menu, then ok

You still need to add the new file to the project, do that via Project / Add Existing Item and select your new file. Or alternatively you may drag/drop the file onto the Solution Explorer.

In general, you probably want to add new files/classes via the Project menu.

mitrmkar 1,056 Posting Virtuoso

now seems to put this whole thing in a weird loop...working on correcting that

I think your header files are missing include guards. So, first, add those in every header file you have, you won't be breaking anything even if you wind up with a setup that actually does not need include guards.

mitrmkar 1,056 Posting Virtuoso

I tried to emulate a wrong filename by simply commenting out the header file and I got a much longer list of errors, including "Month thisMonth" being invalid so it seems to be finding the header file ok (as the error goes away when 'include "dateimpl.h"' is uncommendted out

That makes it pretty certain that this dateimpl.cpp file is not included in the compilation. So you just have to find a way how to get that file included in the compilation. Unfortunately I don't know how it is done in KDevelop, but here is a link to the The User Manual to KDevelop: Projects.

[EDIT]
I see you've rearranged things.

Pertaining to the most recent problem; the Month::intVal syntax would only be used if the Month class would have a static member variable intVal i.e.

class Month
{
    static int IntVal;
    // .. or perhaps const static value
    static const int IntVal_2;
};

int Month::IntVal = 42;
const int Month::IntVal_2 = 42;
mitrmkar 1,056 Posting Virtuoso

it reads for the first time, untill i close the program, but it repeats the information while reading it, it shows only one item

displayList() really is not reading anything from the file. It only displays the values off the current list's head over and over again (if it manages to enter the loop).

>>How would i change that?
Actually, is it clear to you what this displayList() function is supposed to do? Is it only supposed to display the data stored in the file or perhaps something else?

mitrmkar 1,056 Posting Virtuoso

hi...can anyone give me the coding for the library management. I realy need that coding to my study. I need it A.S.A.P. Please...:(

Hi,

Perhaps read; We only give homework help to those who show effort

mitrmkar 1,056 Posting Virtuoso

but still number "2" in menu crashes...i think i am having problem with displaying content of the file.

You are not reading from the file anything. So, it will likely turn out to be an infinite loop there.

mitrmkar 1,056 Posting Virtuoso

I have a button caption, i know its a button and i have its handle...

Are you sure about that? FindWindowxx() may very well return NULL. So, first thing to do, would be to add code that checks that you actually receive handles to those windows. Upon failure, you may get some insight by calling GetLastError() to see what the error code is.

mitrmkar 1,056 Posting Virtuoso

>> But even configure fails.
This sounds too familiar to me .. I'd suggest that you try Cygwin instead of MSYS. I once failed to get GCC compiled on MSYS, but managed to get it done on Cygwin without too much of a hassle. On MSYS, the configure scripts simply kept failing, likely due to the way paths were handled. So, I ditched MSYS and haven't been missing it ever since.

mitrmkar 1,056 Posting Virtuoso

If you still have the following code ..

int n = 0;   
int* list = new(nothrow) int[n];

then you are thrashing memory (you'll get a pointer to a zero-sized memory block). So you need to re-think how to allocate the memory. Also make sure that the allocation succeeds i.e. check that new [] did not return NULL.

[EDIT]
Remember to

delete [] list;

too.

mitrmkar 1,056 Posting Virtuoso

Ah thanks the problem was the brush and the pens, I used

SelectObject( hdc, CreateSolidBrush( etc... ) );

Seems like you have been leaking GDI objects. You might be interested in reading Pushing the Limits of Windows: USER and GDI Objects – Part 1.

>> Another problem that Ive been getting is Blues screens of death, about 3-4 so this worries me.
That's likely due to a malfunctioning driver/hardware, user mode programs don't (directly) cause BSODs.

>> When I check for the last error, it tells me that it is a invalid handle. Just doesn't tell me to what.
What is the failing function in question here?

mitrmkar 1,056 Posting Virtuoso

I think this is what you were after, note that you need an instance of the class through which you make the call ( pB = new B; below)

#include <iostream>
struct B;
struct A
{
  B * pB;

  A();
  ~A();

  void func(int i, const char * p) 
  {
    std::cout << i << std::endl << p << std::endl;
  }
};

struct B
{
  void (A::* funcptr)(int, const char *);
};

A::A()
{
  // a B is needed
  pB = new B;
}

A::~A()
{
  delete pB;
}

int main()
{
  A * pA = new A;

  pA->pB->funcptr = &A::func;

  (pA->*(pA->pB->funcptr))(2, "Lol");

  delete pA;

  return 0;
}
mitrmkar 1,056 Posting Virtuoso

I have v. 8.02 too and for me, F9 really toggles a breakpoint (I think I'm using the default settings, not sure though). Anyway, it's probably best to open the Build menu and see what key does the trick.

mitrmkar 1,056 Posting Virtuoso

I hit F9 key of my keyboard, the programme didn't run.

On my Code::Blocks, F9 toggles a breakpoint. But to compile/link and run the program, you probably want to use F12. See the Code::Blocks' Build menu.

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

>> Well, those were desperate attempts to ..
Try to keep cool and go through the code making sure that you don't mess with the memory anywhere.

As to the original crash with fread() , there seems to be a malloc() , involved. Regarding that, make sure that you are allocating a reasonable memory block ( imageSize > 0 ) and that the malloc() actually succeeds.

mitrmkar 1,056 Posting Virtuoso

well theres no error. lol....

Consider getting a 'second opinion' by e.g. downloading and installing Code::Blocks (~15 MBs), i.e. you might get it up and running in no time. Then you might post back with what the new compiler is telling you.

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

I receive no warnings/errors during compile (using Dev-Cpp, WinXP)

That is too hard to believe, given that you have there ..

FILE file  = fopen(path, "rb");

So, could you verify that you are actually posting the relevant code?

mitrmkar 1,056 Posting Virtuoso

Line 59 is missing the ending semicolon, so ..

float number ;

Fixing that should take care of the first three errors.
Note that the variable LENGTH is OK as is, because it is const , so you don't have to change it in any way.

[EDIT]
As implied/suggested both above and below, I also suggest that you switch to a modern compiler, rather sooner than later.

mitrmkar 1,056 Posting Virtuoso

Adding to what's already been said, line 125 is wrong, sizeof(array) is equivalent to sizeof(int *) there, so you have to know the correct array size there.

"Establish The Size Of Array" could ensure that the given array size is reasonable and the allocation succeeds (e.g. now it accepts and attempts allocations of sizes < 1). Consider changing to [I]size_t[/I] size_of_array; .

In general, upon allocation, check the return values of malloc()/calloc() against NULL.

mitrmkar 1,056 Posting Virtuoso

Actually in C++ you would want to be avoiding malloc() in the first place and using new instead. So ..

// No need to cast anything
 f * node = new f;

[EDIT]
If you (for some reason) use malloc() , you can still use C-style casts to some extent, (i.e. in this case (f*) ) or a C++ cast. But perhaps remember, that casts are best avoided.

mitrmkar 1,056 Posting Virtuoso

I've seen it before :)

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
hashTable::hashTable(int size) {
// A variable local to the constructor used here,
// such vector object would be destroyed the moment
// this constructor call is finished.
//// vector<list<string> > theLists (size);

  // Instead use the member variable vector and
  // allocate the requested amount of lists ...
  theLists.resize(size);
  currentSize = 0;
  // Note that using 'tableSize' is redundant, since the
  // theLists.size() will tell you the same thing.
  tableSize = size; 
}

So the theLists vector was never allocated ( .resize() ), leading to those seg faults when trying to access the non-existent data.

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

How about another approach where some functionality is enabled only when there is some user input? Maybe this would suit you better, if not, just discard this post.

Anyways, that would look like ..

// in message map ..
ON_EN_UPDATE(IDC_EDIT_CTRL,  OnUpdateEdit)

// Handler for EN_UPDATE
void someDialog::OnUpdateEdit() 
{
    // m_button - a member variable of type CButton
    // m_edit -  a member variable of type CEdit

    // toggle the window's state based on whether there is
    // any user input at all in the edit control ...
    m_button.EnableWindow(m_edit.GetWindowTextLength());
}
mitrmkar 1,056 Posting Virtuoso

>> so I'm really just searching for the last occurrence of a slash or backslash.

Have you considered string::find_last_of()?

mitrmkar 1,056 Posting Virtuoso

Still doesn't work I even tried to make second variable a string still doesn't work :(

OK, now focus on your while() loop's exit condition. How does it actually work, given the way you have coded it?

mitrmkar 1,056 Posting Virtuoso

You might post the revised code.

mitrmkar 1,056 Posting Virtuoso

If your program is a regular GUI application, then you might consider using the code from Detecting Media Insertion or Removal. I.e. not involving RegisterDeviceNotification() at all.

mitrmkar 1,056 Posting Virtuoso

If you are the owner, you can still re-write the Dacl and recover that way. Also, you may resort to enabling the privileges SE_RESTORE_NAME and SE_BACKUP_NAME and you should be good to go (take ownership etc).

A handy open source utility for you to study might be SetACL

PS. If you mean, that you have a NULL-Dacl instead of an empty one, then everyone has full access to the object.

mitrmkar 1,056 Posting Virtuoso

Ill go ask in another forum, because I started yesterday and I want to know whats wrong, not that you should explain the basics. TY

You really need to take a look into the basics, one basic -> C++ Tutorial.
Perhaps start at Chapter 1, if you are interested in that tutorial.

mitrmkar 1,056 Posting Virtuoso

If you are just starting with the Visual Studio, then you might look into the VS Help. There are lot of basic "How Do I do .." this and that with Visual Studio.

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.