mitrmkar 1,056 Posting Virtuoso

Here is what I have so far. Suggestions??

Compile the code and start working through the errors/warnings from top to down. Once you think you have solved/fixed a specific error, re-compile and see the results, i.e. don't try to fix all errors at once.

Ancient Dragon commented: Good suggestions. +26
mitrmkar 1,056 Posting Virtuoso
class coord
{
private:
	int xx;
	int yy;
public:
	int getxx(void);  
	int getyy(void);

Hmm, xx and yy are private member variables, whereas getxx() and getyy() are not. So you have to use these public getters that are there, so you ...

if(asteroid1.getxx( ) == asteroid2.getxx( ) && asteroid1.getyy( ) == asteroid2.getyy( ))
// ..

:)

Suicidal_tool commented: Fantastic Help..Thank you! +1
mitrmkar 1,056 Posting Virtuoso

In Visual Studio, open

Project properties / Configuration properties / Linker / Input / Additional Dependencies

and add Advapi32.lib there.

mitrmkar 1,056 Posting Virtuoso

>> I am basically creating everything by hand here (dialogs and all)
Doing all that manually, might also result in increased permanent loss of hair, hence I'd suggest that you check out; ResEdit / free Resource Editor for Win32 programs. It's a quite serious application in it's own right.

mitrmkar 1,056 Posting Virtuoso

I was not trying to trash anything.

I didn't mean to say/imply that you were intentionally trying to trash anything just to see what happens, you misunderstood me somewhat there.

>> 1. What is wrong with leaving the size of a2 undefined
You must be in full control of the memory you allocate at all times, i.e. you have to know the size of a given block of memory you've allocated and keep track of it (what do you think was the size of the block allocated for a2??). Otherwise you'll end up writing to memory, which may be reserved/used for something else. In this case it was and produced the nasty side-effects. The pointers don't automatically adjust the size of the memory block pointed to.

>> How could this have affected output streams in an apparently unrelated function?
Again, you simply trashed the memory ( pointer2[i] = pointer1[i] )

>> 2.And what is the proper way of copying structs?
One way is to allocate enough memory and do a memberwise copy. Also you might be interested in checking out overloading the assignment operator (=), which would be more suitable for non-POD types (Plain Old Data).

mitrmkar 1,056 Posting Virtuoso

See WM_SYSKEYDOWN and WM_SYSKEYUP.

mitrmkar 1,056 Posting Virtuoso

I appear to have hit a memory limit in visual studio.

Since you are trying to allocate rather huge amounts of memory (2GB), I'd guess that the limitations are more probably imposed by your operating system (which one is it?) than the std::string implementation.

See MSDN documentation on Memory and Address Space Limits. Are you perhaps reaching the 2GB user-mode virtual address space limit there?

PS. As already suggested, perhaps process the file in much much smaller chunks than what you are now planning.

mitrmkar 1,056 Posting Virtuoso
warning: format %d expects type int, but argument 3 has type __off_t

Change %d to %ld . That'll most probably fix it, %ld tells that the argument will be long int . If the warning persists, post back.

[EDIT]
Badly beaten by AD it seems, though I'm still in favour of trying %ld

mitrmkar 1,056 Posting Virtuoso

however the cin doesn't seem to be working - I'm getting the initialised value of 0 for n no matter what I enter.

That's because you are passing n by value. You need to pass it by reference instead, i.e.

double gauss(fun f, double a, double b, int & n)
{
    cout << "\n********** GAUSS QUADRATURE **********"<< endl;
    cout << "For the equation f(t) = t^2" << endl;
    cout << "Enter the quadrature order, n you wish to use: " << endl;
    cin >> n;
    cout << "Enter the interval of integration, [a,b]: " << endl;
    cin >> a >> b;
}
mitrmkar 1,056 Posting Virtuoso

what I have done wrong?

To point out basic errors, see the comments below

#include<iostream>
#include<vector>
#include<cmath>
#include<iomanip>

using namespace std;

class tabledata {
    private:
        long double abscisass[28];
        long double weights[28];
    public:
        void set_values();
}  

// a global variable here, will you be using it? If not, delete it.
table;   

void tabledata::set_values () {

    // Both arrays are of size 28 -> the last index
    // you are allowed to use is 27, NOT 28

    abscisass[28] = 0.9739065285171717200779640;
    weights[28] = 0.0666713443086881375935688;
}

int main()
{
    // Here you have two uninitialized arrays
    long double abscisass[28], weights[28];

    // The variable name 'table' clashes with the one
    // you already have as a global variable, 
    // do something about it.
    tabledata table;
    table.set_values();

    // Here you illegally (again out-of-bounds) access the 
    // still-uninitialized 'weights' array local to this function.
    // Shouldn't you be using the 'table' instead?
    cout << "the answer is " << setprecision(25) << weights[28];

    return 0;
}
mitrmkar 1,056 Posting Virtuoso

That's good to hear. But after all, maybe it still would be better to put the game aside for some time, and learn how to use functions/structures instead. What do you think? This is just to say that don't overdo yourself with a single function consisting of several hundreds of lines of code.

mitrmkar 1,056 Posting Virtuoso

A basic tutorial that might come in handy is theForger's Win32 API Programming Tutorial.

mitrmkar 1,056 Posting Virtuoso

I missed the brackets for the check array in the if statement.

There is more than just the brackets here, i.e.

// not "\n", but instead ...
if ( check[0] != '\n' )
Grn Xtrm commented: brackets among other things... :) Thanks +2
mitrmkar 1,056 Posting Virtuoso

i cant figure out wherez the error or at which line exactly, can u guyz specify which line/s?

Sigh, surely you must understand by now, that it's practically impossible to believe that You wrote that code yourself, right?.

Anyway, perhaps read this

mitrmkar 1,056 Posting Virtuoso

So does anyone know how to make use of getline() for this?

You were on the right track (i.e. getline()) in the beginning, so you might get the input doing e.g. the following:

#include <iostream>
#include <string>

using std::string;
using std::getline;
using std::cin;
using std::cout;

int main()
{
    string input;
	
    // Let the user type in the whole line ...
    getline(cin, input);
	
    // What did we get?
    cout << "[" << input << "]";
	
    // Todo: iterate over the input extracting the individual 
    // words, using e.g. a stringstream

    return 0;
}
mitrmkar 1,056 Posting Virtuoso

I would like to put the string day[7]; as private since the days of the week will never change

Given the above code, you might have the string day[7] as a private member variable. So you must be doing something illegal in the code that you did not post.

Furthermore, why not make that a private static const member variable, so you'd have

class dayOfTheWeek
{
public:
    // <snip>
private:
    static const std::string days[7];
};

// and outside the class declaration ...
const std::string dayOfTheWeek::days[7] = 
{
    "Sunday",
    "Monday",
    "Tuesday",
    "Wednesday",
    "Thursday",
    "Friday",
    "Saturday"
};

If you don't make it a static member variable, then every instance of the dayOfTheWeek class has an unnecessary copy of that data (wasting memory).

Ancient Dragon commented: Good post +25
mitrmkar 1,056 Posting Virtuoso

Here's a start:

#include <iostream>

int main () {
     std::cout <<  "welcome to my program";
     return 0;
}

Sorry niek_e, but that's not actually useful since the OP is to write a C program (according to the instructions given)
;)

Nick Evan commented: touche! +12
mitrmkar 1,056 Posting Virtuoso

But the codes works properly when G=280 and l=3...

Since you are unwilling to post any code, I guess that you have this

const int G=290;
const int L=3;
float ReplicatedMat[G+1][L];

inside a recursive function eventually causing the stack overflow.

[EDIT]
Perhaps run the program in the debugger and at the point of the stack overflow, view the Call Stack. That might tell you something useful.

mitrmkar 1,056 Posting Virtuoso

That is not quite correct, see comments

int main(void)
{
    /* Declare the '2D Array' */
    char ** ptr = new char * [5];
    ptr[0] = new char[20];
    ptr[1] = new char[20];
    ptr[2] = new char[20];
    ptr[3] = new char[20];
    ptr[4] = new char[20];

    /* Put some data in the array */
// below you lose all the above allocated 20 byte chunks because you 
// re-assign the pointers to strings, meaning that you cannot anymore 
// delete the allocated memory, which you should do
    ptr[0] = "Hello ";
    ptr[1] = "wond";
    ptr[2] = "er";
    ptr[3] = "ful";
    ptr[4] = " world !!!";

// instead you should e.g.: strcpy(ptr[0], "Hello ") and so on ..

    /* Print the array on the screen */
    for(int i = 0; i < 5; i++)
        cout << ptr[i];

    cout << endl;

// you are not deleting the 20 byte chunks here

    /* Cleanup */
    delete[] ptr;

    /* Wait for the user to press ENTER */
    cin.get();

    /* Tell the Operating System that everything went well */
    return 0;
}
tux4life commented: Thank you very much for correcting me ! +1
mitrmkar 1,056 Posting Virtuoso

So what looks to be the problem?

There might be many reasons, e.g. any application you have open may also abort the shutdown (since you are not forcing it), maybe your system does not support the power-off feature or your program lacks the shutdown privilege etc.

To get a bit more clue about what is going wrong, check which error code GetLastError() returns immediately after the ExitWindowsEx() call ... I.e.

if( ! ExitWindowsEx(...))
{
    // maybe lastError will tell something useful ...
    DWORD lastError = GetLastError();
}

Note that even if ExitWindowsEx() returns non-zero, it does not necessarily mean that the shutdown will eventually occur. (Read the MSDN documentation carefully and (try to) understand it.)

You might also try the How to Shut Down the System sample function (it shows how to enable the shutdown privilege among other things).

mitrmkar 1,056 Posting Virtuoso

I'm running MSVC 6.0 on Vista Home Premium

Umm, maybe you misunderstood me (?). I was not trying to say that MSVC 6.0 cannot be used on Windows versions later than "Windows Server 2003".

Instead, I was trying to say that the "Windows Server 2003 Platform SDK" is the last SDK version that is compatible and works with MSVC 6.0.

Ancient Dragon commented: I re-read your post and you are right -- I misread it. +36
mitrmkar 1,056 Posting Virtuoso

Okay so i have windows XP, Microsoft Visual C++ 2008 Express Edition, what SDK do i need?

You might look at Using Visual C++ 2008 Express with the Windows SDK

Nick Evan commented: Good link +14
mitrmkar 1,056 Posting Virtuoso
mitrmkar 1,056 Posting Virtuoso

To get 'non-destructive writes', open the file specifying also the ios::in mode.

mitrmkar 1,056 Posting Virtuoso

Yes, as your advice, i add the output of "n",
the result is "1026".(it should be 0x402)

By the MSDN:
0x402 An unknown error occurred. This is typically due to an invalid path in the source or destination. This error does not occur on Windows Vista and later.

So i guess the fail may from the "invalid path". is it right?
(But in my PC, the path is true, with out any problem.)

Both the pFrom and pTo members need to be double-null terminated, see the
SHFILEOPSTRUCT Structure documentation.

Nick Evan commented: Good catch, thanks! +14
mitrmkar 1,056 Posting Virtuoso

IsWindowVisible() might be useful.

William Hemsworth commented: Long time no see :) +6
mitrmkar 1,056 Posting Virtuoso

Well, by doing the following ...

...
background = load_image("background.bmp");

if(background == NULL)
{
    // load_image() failed ...
    cout << "load_image() failed, error: " << SDL_GetError() << endl;
}

apply_surface(100, 100, message, screen);
...

I got output as follows:

load_image() failed, error: File is not a Windows BMP file

Xarver commented: Thanks +1
mitrmkar 1,056 Posting Virtuoso

Try with these changes

//CUSTOMERDLL.H
#ifndef DllH
#define DllH
#include "customerForm.h"
extern TCustomerF* DllCustomer;
//---------------------------------------------------------------------
void __fastcall Search (AnsiString, AnsiString, TIBTable*);
extern "C" __declspec(dllexport) __stdcall void CreateCustomer(TComponent *Owner);
//---------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------
//CUSTOMERDLL.CPP
#include <vcl.h>
#include <windows.h>
#pragma hdrstop

#pragma argsused
#include "customerdll.h"

TCustomerF* DllCustomer = NULL;

int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
	return 1;
}
//---------------------------------------------------------------------------
void __stdcall CreateCustomer(TComponent* Owner)
{
	DllCustomer = new TCustomerF (Owner);
	DllCustomer->ShowModal();
}
//----------------------------------------------------------------------------


void __fastcall Search (AnsiString NameP, AnsiString FieldP, TIBTable* Table)
 {

	TLocateOptions Opts;
	Opts.Clear();
	Opts << loPartialKey;
	Opts << loCaseInsensitive;
Table->Locate(FieldP,NameP, Opts );
 Table->IndexFieldNames=FieldP;
}
//---------------------------------------------------------------------------

Try reading up on usage of extern , once you get the idea of it, you might reorganize the code a bit (you already have one extern TCustomerF* declaration there but it seems that you are not using it)

uim_1977 commented: I was so easy.. Thank you MAN!!!! +1
mitrmkar 1,056 Posting Virtuoso

I think you are using a 32-bit toolset (VS Express) and trying to link with the 64-bit version of libmysql.lib.
The 32-bit version of libmysql.lib comes with those missing symbols, what you have is the 64-bit library.

Ancient Dragon commented: You nailed it. :) +36
mitrmkar 1,056 Posting Virtuoso

You might try something like ...

#include <iostream>
using namespace std;
struct test
{
	void myfunction()
	{
		cout << "myfunction()\n";
	}

	test()
	{
		myfunction();
	}
};

static test testing;

int myfunction2()
{
	cout << "myfunction2\n" << endl;
	return 43;
}

static int test2 = myfunction2();

int main(void)
{
	cout << "main()\n";

	cin.get();

	return 0;
}

I'd be interested to know why is this important to you?

[EDIT]
However, the safest way is simply to call your function first thing in the main(), i.e. not relying on the order of initialization.

VernonDozier commented: Impressive. +7
mitrmkar 1,056 Posting Virtuoso

Ive been trying to look that up for a while now using the 'help' provided by the borland compiler but i cant seen to find anything that i can make sense of unfortunately

Here is how you get items of a single (selected) row

TListItem * Item = ListView1->Selected;
if(Item)
{
    AnsiString text = Item->Caption;
    TStrings * subItems = Item->SubItems;

    for(int ii = 0; ii < subItems->Count; ++ii)
    {
        text += ", " + subItems->Strings[ii];
    }
}
tootypegs commented: cheers for the help! +1
mitrmkar 1,056 Posting Virtuoso

Most of the people who are posting their question over here or sharing their problems are students.
I have posted that code to work on freely available compiler such as TurboC.

But really consider that presumably TurboC was released before most of the students posting here were even born. So, please do not advertise an antiquated/out dated tool for these students. (If anyone is interested in TC, it is available for free from Borland, tagged as antique software ;) )

Nick Evan commented: Sounds like good advice to me! +8
mitrmkar 1,056 Posting Virtuoso
int _stdcall sampleFunc(int iVar, char cVar){
    //Code here
    ...
}
typedef int (*myFunc)(int, char);

Your myFunc typedef does not match the DLL function's signature because you've omitted the calling convention from the typedef (by default, VC++ uses the _cdecl calling convention). So you need to have

typedef int (_stdcall *myFunc)(int, char);
murderotica commented: Explanation is good. The answer is flawless. +1
mitrmkar 1,056 Posting Virtuoso

Go through the stored items in the Library 's destructor and explicitly delete the items there.

Undertech commented: Definitely something important that I didn't realize! +1
mitrmkar 1,056 Posting Virtuoso

Since you have printVector(vector<T> & x) pass by reference ... printVector( x );

mitrmkar 1,056 Posting Virtuoso

One obvious little error ... if( jump = true )

William Hemsworth commented: Well spotted :) +3
mitrmkar 1,056 Posting Virtuoso

I dereference them once to get access to LOD, but this doesn't seem to work. Why not?

Dereferencing was actually missing ... i.e.

if( (*(visualEntity.begin() + i))->LOD == wantLOD){
mitrmkar 1,056 Posting Virtuoso

whoops, I meant to say,

push the FILENAME object (that is on the heap) into the list called "files"..

is that right?

No, the point is that the specific object that you have on the heap, is NOT stored into the list. Instead, the derefenced pointer which you supply to push_back(..) is only used to construct another object (via copy constructor) that IS stored into the list. The initial object on the heap will happily remain there unless you issue delete on it.

I did not declare my list as: list <FILENAME *> files;

I know, I wrote "If your list would be declared as list <FILENAME *> files;", maybe you missed it.

Could you clarify what you meant with the last paragraph?

isn't this a pointer/heap allocation:? FILENAME* filePtr = new FILENAME;

Yes it is.

Once again ... no pointers/explicit heap allocations whatsoever need to be involved. I.e. you can write:

vector < FILENAME > files;
string fname;

for( ... some loop condition here ... )
{
    fname =  ... some code here that builds the file path ...

    FILENAME file;
    file.SetFullPath(fname);
    // invoke copy constructor and store a new object (a copy of the 'file' object) 
    files.push_back(file);
}
krebstar commented: Thanks :) +1
mitrmkar 1,056 Posting Virtuoso

Im not sure what you mean by passing the address of the structure, and not the struct itself?

You are missing ...

bResult = DeviceIoControl(hDevice,  // device to be queried
      IOCTL_DISK_GET_DRIVE_GEOMETRY,  // operation to perform
                             NULL, 0, // no input buffer
                            & pdg, sizeof(pdg),     // output buffer
                            &junk,                 // # bytes returned
                            (LPOVERLAPPED) NULL);  // synchronous I/O
tootypegs commented: thank you for your help +1
mitrmkar 1,056 Posting Virtuoso

Try not to use the goto , have you considered using break instead

for(int i=0; i<10; i++) {
 if (i > 0)
  break;    // <- breaks out of the for loop ...
else
  cout << i;
}
OmniX commented: Thanks for the help +1
mitrmkar 1,056 Posting Virtuoso

Futhermore, you have the variables the wrong way around, i.e. instead of a >> strin; use strin >>a;

Nick Evan commented: Duh... Missed that completely +8
OmniX commented: Thanks for the help +1
mitrmkar 1,056 Posting Virtuoso

Any guidance on how to polish this code up would be greatly appreciated.

The code needs proper, consistent indentation.

Salem commented: It certainly does! +19
mitrmkar 1,056 Posting Virtuoso

I have read about Object Serialization in my JAVA book. Could it be possible with C++?

See e.g. here

Prabakar commented: thanks +1
mitrmkar 1,056 Posting Virtuoso

The function is malloc() , not maloc().

mitrmkar 1,056 Posting Virtuoso

I would also like its modified time and date.

See e.g. RegQueryInfoKey()

Ancient Dragon commented: You're right :) +32
mitrmkar 1,056 Posting Virtuoso

At least a couple of severe errors ...

...
payroll *employee[6], *report;
// here you call printreport() through an uninitialized/unallocated pointer, 
// it is a big no-no 
employee[0]->printreport();
int i=0;
char aemployeename[14],apaystat;
double ahoursworked, ahourlyrate, minnp,maxnp, netpays[6];
void sortnetpays(double netpays[], int i);
// here you do it again ...
report->printheaders(); 
...

Last but not least, I'd really suggest you to format the code in order to make it readable. You'd be doing a favour to yourself first and foremost, I think.

Nick Evan commented: A lot of people underestimate the benefit of code-formatting +6
mitrmkar 1,056 Posting Virtuoso

I've changed the whole functions in LinkList class and Node Class to take this kind of parameter (const string &x)

and I ended up with two error messages from the compiler *they're the same*
: error C2678: binary '=' : no operator defined which takes a left-hand operand of type 'const class std::basic_string<char,struct std::char_traits<char>,cla

!!! what should I do?

For example the remove() function cannot be passed in a [B]const [/B]string & , because the function modifies the argument. So you need to have ... bool remove ( std::string & x );

Q8iEnG commented: Perfect member :) +1
mitrmkar 1,056 Posting Virtuoso

and when add this statment
(word.substr(word.find(' '))
,appear problem in the run (abnormal program termnation)

Here is one way to trim leading whitespace

string test_string = "    test_string";
    string ws = " \t";

    // lookup the position of the first non-whitespace char, if any
    std::string::size_type pos = test_string.find_first_not_of(ws);

    if(std::string::npos == pos)
    {
        // string contains only whitespace
    }
    else
    {
        // drop the leading whitespace
        test_string.erase(0, pos);
    }

    cout << "[" << test_string << "]" << endl;
Nick Evan commented: nice & clean example +6
mitrmkar 1,056 Posting Virtuoso

so plz tell me what is the solution for it??

Pick up the habbit of using e.g. the following compiler options -W -pedantic -Wall.
When you compile, work through the error/warning list until your program compiles cleanly.

Here is a guide
http://gcc.gnu.org/onlinedocs/gcc-4.3.0/gcc/Warning-Options.html#Warning-Options

iamthwee commented: YES - although that isn't how you spell habbit. +15
mitrmkar 1,056 Posting Virtuoso

by the way one more thring if i create a .def file for a .dll and from the def file i found out that a certain function takes 3bytes e.g@3, is it ok to edit the .def file to make it take 4 (as we did) e.g changing the @3 to @4 or shouldn't i change the header file to suite the .dll needs

It appears that you are confused by the link ordinals in the .def files. If you take a look at the original .def file, there may be e.g a line like

LT360LIB_OpenLinkUSB         @2   ; LT360LIB_OpenLinkUSB

The '@2' is the ordinal which also can be used for linking, i.e. linking completely without the symbolic function name. So, don't modify/remove those ordinals, just append the function naming decoration to the function names, e.g.

LT360LIB_OpenLinkUSB[B]@0[/B]         @2   ; LT360LIB_OpenLinkUSB

and so on.


Now, as a check-list, using LT360LIB_OpenLinkUSB() as an example, things should look like:

In the header file:

extern "C" __stdcall LONGINT LT360LIB_OpenLinkUSB(void);

In the .def file

LT360LIB_OpenLinkUSB@0          @[I]<link ordinal>[/I]

In the generated .lib file: (use dumpbin /EXPORTS)

[I]<link ordinal>[/I]            _LT360LIB_OpenLinkUSB@0

And in the code

LONGINT val = LT360LIB_OpenLinkUSB();
mike issa commented: exactly the answer needed +2