mitrmkar 1,056 Posting Virtuoso

Error NONAME00.CPP 13: Declaration terminated incorrectly

A semicolon is missing *c= *a + *b; And you could also clearly state that main() returns an int . So rather make it ..

int main()
mitrmkar 1,056 Posting Virtuoso

Still got 1 error.

Tell us what the error is ...

[EDIT]
To be more clear; tell us the compiler error message, if you are receiving one.

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

Change the function's return type to void and pass the third argument also as a pointer. (Though this first version that you have is more 'natural'/usable, i.e. it returns the calculated value.)

mitrmkar 1,056 Posting Virtuoso

When cin encounters Ctrl-Z, cin.eof() will return true. So e.g.

if(cin.eof())
{
  cout << "bye ...";
  return 0;
}
mitrmkar 1,056 Posting Virtuoso

Have you thought about forgetting the char arrays and using std::string instead? Consider for example

// Read in the line from data.txt, in one go
string line;
ifstream ifs("data.txt", ios::in | ios::binary);
if(getline(ifs, line))
{
  cout << "read: " << line << endl;
}

But if you insist on using char arrays, then fix the first strcat() by replacing it with strcpy() , so ..

char argv2[ <a reasonably large value here > ]; //will store argv[1] (path)
strcpy(argv2,argv[1]);

The way you have it, is definitely wrong, argv2 is uninitialized there and the strcat() is likely to end up trashing memory.

At any rate, be prepared for paths longer than 80 chars, a reasonable max path length would be 260 chars (which is MAX_PATH on Windows).

mitrmkar 1,056 Posting Virtuoso

Now, the problem I am facing is that when I read the file, I am shown the value two times.

Simply don't use .eof() in the loop control, it does not work as you may think it does. Rather do..

while (fr.read((char *) &s, sizeof s))
{
  printf(...);
}

Maybe see Why does my input seem to process past the end of file?

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

AboutDlgProc is the dialog procedure (a function) that will handle displaying your About dialog box. The compiler has not seen the AboutDlgProc() function at the point where the error occurs.

Do you have that function in that .cpp file?

mitrmkar 1,056 Posting Virtuoso

>>I get quite a ew warnings around 76 ..
Choice to ignore warnings is all yours (I hope you do know what you are doing though).

I'd would assume some sort of VS failure, in terms of building a proper binary, but then again who knows.

mitrmkar 1,056 Posting Virtuoso

Hmm, main is without parenthesis there, so I assume that you just typed that piece of code as an example, instead of copying it from the program's code.

Increase the warning level to the highest (W4) and rebuild the project. What does the compiler say?

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

Is your code using assert() or any of the VS macros wrapped around assert() ?
Furthermore, have you written e.g.

#ifdef _DEBUG
.. do something here ..
#endif

If you have, then make absolutely sure that you are not changing anything via those pieces of code.

mitrmkar 1,056 Posting Virtuoso

Please forget missing library files, as a matter of fact, what do you actually mean by missing library files?

The only way that it seems to run succesfully (that is, without crashing), is to have it read an empty input file.

[EDIT]
What compiler are you using ..

- at school:
- at home:

mitrmkar 1,056 Posting Virtuoso

Try specifying the full path to the .ico file, like

hIcon = (HICON) LoadImage(NULL, "c:\\full\\path\\to\\menu_two.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE);

GetLastError() gives you an error code that might be helpful when figuring out the reason of a failing Win API call. See an example of
Retrieving the Last-Error Code

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

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

Arrival.h:7: error: expected class-name before ‘{’ token

#ifndef ARRIVAL_H
#define ARRIVAL_H

#include "Event.h"

using namespace std;

Most likely you are not including anything from the std namespace via the Event .h, so the namespace std remains unknown to the compiler and cannot be used there. I.e. perhaps remove the using namespace std; altogether, (if there will be no use for it in that header file). Otherwise, #include the necessary headers and you'll be able to keep the rest of this header file as is.

mitrmkar 1,056 Posting Virtuoso

I have tried that but this does not produce an output on the screen. I always seem to have to use the newline character (\n) in order to get anything.

Have you tried fflush(stdout); ?

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

Can you please explain what you meant by "> program.exe 123 456"?

Actually, there are two arguments

Actually there are three, from the program's point of view, that is. The name of the program itself counts as one argument. Aia pointed that out ^^ but I think you missed it. So, given that you run the program as follows:

program.exe 123 456

then your program sees ..

argv[0] -> "program.exe"
argv[1] -> "123"
argv[2] -> "456"

and argc would be equal to three.

mitrmkar 1,056 Posting Virtuoso

?Invalid number of arguments
Press any key to continue . . .

int main(int argc, char **argv)
{
    if (argc != 3)
    {
        printf("?Invalid number of arguments\n");
        system("pause");
        exit(1);
    }
}

Well, it is expecting to be run with 2 arguments, if those arguments are not present on the commandline, the program just exits with the message.

So try using it like:

> program.exe 123 456

It seems to be expecting strings that atoi() converts to integers.

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

Perhaps you could post the code you've tried?

mitrmkar 1,056 Posting Virtuoso

Two options to make this sort(...) work, would be

Make the fooSort() a static member function, so ..

[I]static[/I] bool fooSort(const Foo * fooPointer1, const Foo * fooPointer2)
    {
        return fooPointer1->fooMember1 < fooPointer2->fooMember2;
    }

or take the fooSort() function outside of the class completely, so ..

bool fooSort(const Foo * fooPointer1, const Foo * fooPointer2)
{
    return fooPointer1->fooMember1 < fooPointer2->fooMember2;
}

The above is based on what you posted in your initial post. But I hope you get the idea.
Then a couple of things..
- there is a member variable Random [I]rand[/I] , that is bad, since the standard library comes with a routine named rand() , so try to avoid name clashes.
- You are typing in extra semicolons as in

void setFooMemberValues()
{
<snip>
} ;

Depending on the mode you compile with GCC, your code might be totally rejected.

Then you asked what is wrong with the following ..

std::vector<Foo*> fooObjectPointers1;
std::vector<Foo*> fooObjectPointers2;
// The vectors contain nothing at this point, trying to access
// the non-existent element causes the crash
fooObjectPointers2[0] = fooObjectPointer1[0];

A safer way to try to access would be fooObjectPointers2.at(0) , which would give you an exception that could be caught.

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

Windows 7, i've created a registry key before, and it has showed up in regedit before. And yeah i refresh regedit, and reopen it, still no key shows up.

Since Windows XP the registry has been partly virtualized i.e. portions of it actually map to elsewhere as compared to the desired location. So, keys under HKEY_LOCAL_MACHINE are subject to this, so that may be a concern here (i.e. you may be looking in the wrong place in the registry, I'm not absolutely sure though).

Anyway, you being on Windows 7, I'd suggest that you try to create the key under HKEY_CURRENT_USER and see if it makes difference (there should be no virtualization issues there).

mitrmkar 1,056 Posting Virtuoso

I run it again and it opens the key, however i still can't see this key in regedit, after restarting the program multiple times and refreshing.

If you don't see your program output the "Checking for config failed" text, then the key is in the registry, in other words the code uses RegCreateKeyEx() properly. By refreshing, you mean refreshing the Registry Editor's view (i.e. F5)?

Which Windows version you are using?

mitrmkar 1,056 Posting Virtuoso

It looks like you are doing whole lot of extra work there. In addition the code also leaks memory, you allocate using new , but never delete that memory. Remember that you must delete the memory you have allocated.

If your RWCString class is the RogueWave's string class, then you can simplify the code a lot. That class supports e.g. operator == , so I'd suggest that you try the following and post back.

Employee * Employee::readEmpInfo(const char* nickname) {

  std::map<int, Employee*>iterator myptr;

  for(myptr = myEmpData.begin(); myptr != myEmpData.end(); myptr++) 
  {
    // temp variable 'employee' used here to make code more readable
    Employee * employee = (*myPtr).second;

    // RWCString has built-in capability to directly
    // compare against a 'const char *', so use it ...
    if(employee->emp_first_name == nickname)
    {
      cout << "found the employee you are searching for :" 
           << employee->emp_first_name << endl;
    }
  }
}

Then, would you please tell which compiler you are using? The code you've posted really should not compile in the first place. So I'm wondering whether your compiler is quite broken or are you posting somewhat irrelevant code snippets.

PS. Note that at any rate, you don't need to allocate ( new ) any memory inside that function.

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

Adding to what's been said above, GCC spotted a thing in the list() function, it said;

warning: too many arguments for format

That means that the printf(...) call there needs attention. There is a mismatch between the format string and the number of arguments you actually pass in.

Then you might consider dropping usage of fflush(stdin) altogether (as it might produce quite unexpected results), and perhaps replace gets() with e.g. fgets() to be on the safer side.

See ...
Why gets() is bad.
Why fflush(stdin) is bad.

Salem commented: Many fine points that deserved better than an anonymous -1 for your effort +19
mitrmkar 1,056 Posting Virtuoso

i left out initializing total = 0. Why is it important to initialize it to 0 before entering the loop?

Basically, if you don't initialize it, then the initial value may be pretty much anything. The compiler doesn't care, it expects you to do the initialization. Maybe, try it out, put a cout << total << endl; prior to entering the loop and see what the initial value is.

mitrmkar 1,056 Posting Virtuoso

sorry but I really couldn't understand the += operation. Are there any alternate methods?

Well, one way, perhaps more clear to you, would be

float total = 0.0f;
while(looping)
{
  float calculated_value = some_func();
  // add to the 'total' ...
  total = total + calculated_value;
}

So, += is another form of value = value + some_other_value , they both do exactly the same thing;

mitrmkar 1,056 Posting Virtuoso

Perhaps try a simplified version first ...

int main(void)
{
  float total = 0.0f;

  // loop twice ...
  int count = 2;

  while (count --)
  {
    float weight = 0.0f,
          distance = 0.0f,

    cout  << "Item " << count << "Net weight in kg: ";

    cin >> weight;

    cout << "Distance travel in km: ";

    cin >> distance;

    // double the values and sum up ...
    total += 2* weight + 2 * distance;

    cout << "The total cost is now " << total << endl;
  }
  return 0;
}

PS. If you don't have any specific reason to operate with float (such as saving memory), then rather switch to double s altogether.

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

It appears as if

total += weightcount(weight) + distancecount(distance);

would do it. And also initialize total to zero before entering the loop.

mitrmkar 1,056 Posting Virtuoso

I sort of understand what your saying, that the function doesnt care what it is....just where the data starts and ends.

A function does not know where the data ends unless you tell it to the function. So if you pass an array into a function, be sure that the function also gets the information about the array's size (number of elements in it, that is).

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

Something that looks suspicious ...

TitleState::~TitleState()
{
    isCurrentState=false;
    StartButton.OnCleanup();
    SDL_FreeSurface(background);
}
//------------------------------------------------------------------------------
void TitleState::OnExit()
{
     StartButton.OnCleanup();
     isCurrentState=false;
     SDL_FreeSurface(background);
}

I'd say that be sure that you don't free anything twice i.e. don't do SDL_FreeSurface(background) , if the 'background' has already been freed.

Then change

void Out(char* words)
{
     printf(words);
}

to

void Out(char* words)
{
     printf("%s", words);
}

Remember that printf() treats its first argument as a format string. And if that string happens to 'resemble' a format string, printf() expects one or more arguments (which are not present), so you'd likely be heading for a nasty surprise.

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

Post solved, thanks much guys :).

Once you've fixed what's mentioned above, test the program by trying to place your ship at 'A0' for example.

mitrmkar 1,056 Posting Virtuoso

>> except sometimes it does choose the same spot twice, any tips on how to prevent that?

Have a loop in which the computer chooses, so if the location is already used, keep looping until a proper one is found.

Note that the indexes generated by rand() must be within 0..7, inclusive, otherwise you are in trouble.

mitrmkar 1,056 Posting Virtuoso

Sorry but the code you've posted is somewhat vague/insufficient.

By looking at it, even the

>> povbGarniture -> bInserer ((char) szTampon [n]);

should fail. Are you sure that you posted portion of the header file that you are actually using (note that the class declaration is missing the ending brace)?

[EDIT]
Perhaps compile the code with another compiler, if you have one handy.

mitrmkar 1,056 Posting Virtuoso

I think that there is no protection against adding a ship several times to same location (neither for the user nor the computer).

Then are you sure that you have gotten the usage of rand() right, i.e. what does (rand()%8)-1; do?

Then try to type in some unexpected input and watch out for convert() .

PS. Kudos for great formatting.

mitrmkar 1,056 Posting Virtuoso

A remote possibility ... maybe fclose() fails?

mitrmkar 1,056 Posting Virtuoso

A simple suggestion, perhaps try to see what ferror() says?

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

tried to neaten up my code to make it easier to follow.

Most modern IDEs come with a decent auto-formatting/beautifier feature, meaning that you'll get a decent formatting at a click of a button or so. Maybe you have such a feature but don't know about it?

You might want to increase your compiler's warning level to the maximum, in other words, just let the compiler spot the mistakes. If you are using GCC, then compile the code with the -Wall option set (=enable all warnings).

mitrmkar 1,056 Posting Virtuoso

I tried to call memcpy twice but it stored the 1st copy of 4 seconds correctly but not the other copy. I was assuming that once data is copied in the buffer, its memory address automatically points to the next memory block

The pointers don't automatically 'adjust' themselves, no matter what you do. You simply have to specify the memory location where the write is to take place. So, in the second memcpy() , adjust the destination pointer so that it points to the first byte past the first block you've written.