mitrmkar 1,056 Posting Virtuoso

> deprecated conversion from string constant to ‘char*’

The string literals are constants, so using const is in order, like so

const char * months[] = {"january","february","march","april"};
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

All the pointers in the reg array end up pointing to the one and only buffer line that you have. So, every time fgets() grabs new data, any pre-set pointers in the array automatically point to the newly fetched data - the previous data is simply overwritten.

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

>> I could say i find the limit of microsoft's product in engineering computing.

Perhaps see Memory Limits for Windows Releases.

mitrmkar 1,056 Posting Virtuoso

Line #75, connects the last node to the one specified (i.e. temp2) - why? Probably not what you want.

mitrmkar 1,056 Posting Virtuoso

>> I gave up and used a bash call ..

Maybe give it another try .. adding a curl_easy_perform(curl) call there might work wonders ;)

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

>> Here is the same code similar to the C code in C++ to save you the bother.
>> Thread Solved.

Sorry, but I think you should Read This Before Posting .. scroll down to the "Don't give away code!" section.

Nick Evan commented: Yes! +15
jonsca commented: Bin-gooooooooo as Larry David would say +4
mitrmkar 1,056 Posting Virtuoso

To me it's unclear what the program actually is about precisely, but would ClipCursor() be accepted?

mitrmkar 1,056 Posting Virtuoso

OK - you have changed the signature of the Imprime(...) function.

// Your declaration ..
void Imprime(int numerocarro, int numlugar, int situacao, int tempo);
// .. the definition ..
void Imprime(int numerocarro, int numlugar, int situacao, float tempo)

The last parameter has changed from int tempo to float tempo .
Now, you have to decide which way you want to have it and change the code accordingly (i.e. float or int ?). Note that the signatures must match at all times.

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

You might re-post your current main.cpp (I don't think these errors match with the above main.cpp). Also you might Rebuild the whole Visual Studio solution and post the errors.

mitrmkar 1,056 Posting Virtuoso
Ancient Dragon commented: great :) +31
mitrmkar 1,056 Posting Virtuoso

>> i was able to fix more errors!
Nice.

>> there is only one left!
Even better, I think the error comes from the line #19.
Since Aux and Actual both are of type CNoFila * , I'm guessing that your intention was to write ..

// Set Aux to point to the same CNoFila object as Actual does..
Aux = Actual;

//// instead of
//// *Aux = Actual;
mitrmkar 1,056 Posting Virtuoso

>> I have got core dump by running this code
I'm echoing what griswolf said .. post the actual code that gave/gives you the core dump. The code you've posted should not compile with any compiler - because of the missing ')' (line #8).

Anyhow, assuming that your crashing program had the ')', a couple of things ..

How much memory are you actually allocating there, i.e. sizeof(userInput) == ???
How about e.g.

#define SIZE 20
char * userInput = malloc(SIZE);
...

Then, scanf("%s", & userInput) <-> you are passing in a char ** , whereas "%s" expects a char * So, you must write ..

scanf("%s", userInput);

Note that scanf("%s", some_char_pointer_here); can be just as unsafe as the infamous, to-be-avoided gets() , because it is completely unaware about the size of the destination buffer. A safe alternative is to specify the size, like so ..

#define SIZE 20
char my_buffer[SIZE] = "";

/* Note: 19 instead of 20 */
int res = scanf("%19s", my_buffer);

if(res == 1)
  puts(my_buffer);
else
  puts("No luck with scanf() this time ..");

Oh, and maybe see What's wrong with casting malloc's return value?.

I think all the other issues have already been discussed in this thread.

mitrmkar 1,056 Posting Virtuoso

>> Error 1 - error C2011: 'Controller' : 'class' type redefinition 9
An unfortunate space character has slipped in, preventing the definition of the intended CONTROLLER_H macro ..

Controller.h

#ifndef CONTROLLER_H
// #define CONTROLLER _H        // <--- wrong
#define CONTROLLER_H            // <--- right
#include "LevelFolders.h"
...
Nick Evan commented: Nice catch +13
mitrmkar 1,056 Posting Virtuoso

>> I have debugged the syntax errors and now need help with the logic. I think I got
>> one of the logic, so there *should* only be 2 left.

So, if you've gotten the code to compile, it might be worth testing its functionality to see where it goes wrong.

I.e. run very simple tests such as;

1 + 1;
2 * 2;

and so on.

PS. If you already haven't, then try to configure your compiler to produce as many warnings as possible - that might help too.

mitrmkar 1,056 Posting Virtuoso

Good grief .. how come vijayan121's post ^^^ goes so unnoticed here?

Ancient Dragon commented: Good catch :) +28
mitrmkar 1,056 Posting Virtuoso

>> AS U CAN SEE IN MY PROGRAMME ...
Please don't SHOUT, thank you.

As for the problem, I believe closegraph() will do what you want.

mitrmkar 1,056 Posting Virtuoso

If your compiler supports long long , you may

  • get lucky with std::stringstream
  • have strtoll() at your disposal

Though, as Banfa noted, your code will not be standard C++.

mitrmkar 1,056 Posting Virtuoso

>> The debugger itself in 2K8 and onwards will give you the line the exception is thrown
>> on and the stack trace will show you what's been called up to that point.
Actually quite so, I think I was on autopilot - sorry. The above method would do the job when first-chance exceptions would be needed - but in this case, it's not of practical use.

mitrmkar 1,056 Posting Virtuoso

<< I'm using Visual Studio 2008 C++

From the Visual Studio's menu, can you find an option titled
Debug / Exceptions

If you can, then select it, and in the dialog box that opens, select the option;

Win32 Exceptions
..... c0000005 access violation

(I'm looking at VS 2005 at the moment, so your GUI may be different)

After that, just run the game in the debugger and once the access violation occurs, you should be able to locate the code that's causing the exception. See how it goes.

mitrmkar 1,056 Posting Virtuoso

>> I am getting a really weird unhandled exception
What is the exact error message? (there are many exceptions)

Are you using Visual Studio?

mitrmkar 1,056 Posting Virtuoso

>> .. I have already defined pluginList but errors errors errors
>> Below is full error log ..
Hmm, the errors seem mostly pretty trivial (e.g. missing #includes, scope resolution ( std:: ) and function arguments).
So I suggest that you work through the error list (from top to bottom). Try solving one error at a time, then re-compile and see what is the output.
;)

PS.
This is not C++

double [] retVal;

This would be ..

double retVal[ <some const size here> ];

[EDIT]
Regarding this "double retVal[]", it is an array local to the function - so you must not return an address to it, because it's garbage as soon as the function returns. You need to re-think that one.

mitrmkar 1,056 Posting Virtuoso

>> Should I make it typedef?
That is up to you, i.e. how do you want the thing to work?

mitrmkar 1,056 Posting Virtuoso

Umm, maybe

#include <vector>
std::vector<IPlugin*> pluginList;//hold plugin lists

?

mitrmkar 1,056 Posting Virtuoso

You are missing the const in the signatures, I take that you want to keep the methods const, so ..

Addition.h

<snip>

class Addition : public IPlugin{
public:
	const char* getName() const; /* < ---- const was missing */
	const char* getSign() const; /* < ---- const was missing */
	double doMath(double a, double b);

and also fix this same thing in Addition.cpp.

mitrmkar 1,056 Posting Virtuoso

>> Addition.cpp:39: error: because the following virtual functions are abstract:
>> IPlugin.h:7: error: virtual const char* IPlugin::getName() const
>> IPlugin.h:8: error: virtual const char* IPlugin::getSign() const

The code for Addition::getName() and getSign() seems to be missing.

>> Do you mean at end of each file I should put \n?
Go to end of the file and hit ENTER.

[EDIT]
>> but I have implemented them!
The functions' signatures must match, are you sure you haven't forgotten e.g. const somewhere?

mitrmkar 1,056 Posting Virtuoso

It should be __declspec , so ..

#define PLUGIN_EXPORTABLE __declspec(dllexport)

>> Also I don't understand what the warning below means
>> warning: no newline at end of file

You need to add a new-line character at the end of the file.
If you don't, your C++ program has undefined behaviour (believe it or not) ;)

mitrmkar 1,056 Posting Virtuoso

I think you are unnecessarily concentrating on the whitespace.

You might read each line into a std::string, just like you already do, and use a std::stringstream for extracting 3 doubles. If the extraction succeeds, you've got a valid line to output, otherwise treat it as a blank line (maybe with some error checking added, i.e. is it really just spaces plus a newline or perhaps something else).

I think, managing all that would be a good start. Perhaps search DaniWeb for some stringstream examples.

mitrmkar 1,056 Posting Virtuoso

>> ... Obviously it doesn't work ...

Please see Narue's Read This Before Posting, mostly the "Describe your problem clearly and fully!" section.

mitrmkar 1,056 Posting Virtuoso

Explicitly returning a value from main() should not be necessary, the standard says:

If control reaches the end of main without encountering a return statement, the effect is that of executing

return 0;

>> To indicate success back to the kernel, you should return 0, or non-zero if there has been some kind of catastrophic failure ^^

The two pre-defined macros EXIT_SUCCESS and EXIT_FAILURE (from <cstdlib>) can also be used.

jonsca commented: Narue just shed a (happy) tear somewhere... :) +4
mitrmkar 1,056 Posting Virtuoso

>> gcc -o test test.cpp

You are using gcc as the compiler. Since the code is C++ (i.e. not C), you have to compile with g++ instead.

If you are compiling from the command line, just replace gcc with g++, otherwise you have to change your IDE's/project's settings.

mitrmkar 1,056 Posting Virtuoso

>> test.cpp:3:18: error: stream:

There isn't a header file named <stream> in standard C++. Looks like you'd rather want to;

#include <string>

mitrmkar 1,056 Posting Virtuoso

>> 1. Why couldn't the compiler throw and immediately highlight whenever an index beyond 220 was accessed.
Your compiler does not generate code for validating each and every memory read/write - you just have to be very careful.

>> >> Why it was working well with (comparatively) smaller images?
What did d_data->maxGrey-d_data->minGrey yield with those particular images?

>> Why was it running OK when within the main() function as opposed to independently in the stats class?
When you are corrupting memory, generally you might think of it as 'all-bets-are-off'.
You were lucky because the Debug heap management kicked in and spotted errors.

Note that if e.g. your memory block indices are 'suitably off', you may actually be writing to another (valid, allocated) block, silently corrupting data - this is hard to detect and the debug heap management routines are of no help here.

PS. Maybe consider using std::vector s instead of dynamic allocation?

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

WinBGI might do the job. See vegaseat's code snippet; Add WinBGI Graphics to your Console. There's a link to a site from where you can get what's needed -- note that you also need to get a new compiler.

mitrmkar 1,056 Posting Virtuoso

Also note that HP-UX's malloc() may fail if you e.g. have previously tampered with the allocated memory. See http://docs.hp.com/en/B2355-60105/malloc.3C.html - scroll down to DIAGNOSTICS.

mitrmkar 1,056 Posting Virtuoso

Looks like nbaztec and jonsca sorted your problems out.
However, I'd like to point out a basic thing that you've been doing wrong, namely "number_of_users = ++number_of_users".

Do not write code like that, see comp.lang.c FAQ list · Question 3.3

jonsca commented: Yup +4
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

i'm unable to locate where i'm overwriting....

Did you try using a Data Breakpoint?

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

argument of type "const char *" is incompatible with parameter of type "LPCWSTR"

See this codeproject article What are TCHAR, WCHAR, LPSTR, LPWSTR, LPCTSTR etc?

Nick Evan commented: Great link +12
mitrmkar 1,056 Posting Virtuoso

It very much looks like you are overwriting memory somewhere, rendering this optr invalid.
You might get a good clue about as to what is happening by doing the following:

  • Put a breakpoint at the line; optr = fopen("D:\\Puma-TV543-82-OAD-UK-001.txt","wb");
  • Hit F10 to open the file
  • Note down the value of optr (it will be something like 0x00423A90)
  • Add a data breakpoint, using the expression: optr != 0x00423A90
  • Hit F5 to continue, at the moment that optr's value changes, you will break into the debugger

PS. When you post code, please use code tags.

[code]

Your (nicely formatted) code here

[/code]

mitrmkar 1,056 Posting Virtuoso

Just a suggestion in case this ICODE button re-appears.

Would it be possible to display it as e.g. "INLINE", instead of the previous "ICODE"? I think that would cut down the number of posts with code snippets encased in ICODE tags (there are lots of those).

iamthwee commented: good suggestion +0
mitrmkar 1,056 Posting Virtuoso

I'd suggest that you first get the fprintf() -thing working, separately from any other code.

So, try the following and see what it outputs.

#include <stdio.h>

int main()
{
  FILE * fp = fopen("/home/aniroot/logs/log.txt", "a");

  if(fp != NULL)
  {
    /* Write something .. */
    int result = fprintf(fp, "%s", "testing ...\n");

    if(result < 0)
    {
      /* Failed, display error information */
      perror("fprintf()");
    }
    else
    {
      printf("result: %d\n", result);
    }

    /* Try to close the file (also flushes any written output) */
    if(fclose(fp) == EOF)
    {
      /* Failed, display error information */
      perror("fclose()");
    }
  }
  else
  {
    /* Failed, display error information */
    perror("fopen()");
  }

  return 0;
}

You might also check out related functions such as clearerr()/ferror()/fflush().