mitrmkar 1,056 Posting Virtuoso

Are you sure that any fprintf() -calls are actually made? fprintf() returns a value - you might check what you are receiving.

Perhaps write a little fprintf() -test program so that you get familiar with it?

mitrmkar 1,056 Posting Virtuoso

is giving segmentation error when reaching the fprintf() function ......

You have a really nasty bug there, something is wrong with the following line ..

...
if(logs = NULL)
...

Furthermore, if you fail to open the log file, then you must NOT try to fprintf() anything to it (otherwise, the result is the same as now - a crash).

PS. Have you checked that the compiler is not giving any warnings?

lionaneesh commented: Nice answer thank you!!!! +0
mitrmkar 1,056 Posting Virtuoso

Which WM_ message are you processing?

mitrmkar 1,056 Posting Virtuoso

check if the shift key is being held down when processing use input?

I believe GetKeyState() will do the work, see an example of it here Using Keyboard Input

mitrmkar 1,056 Posting Virtuoso

Ancient Dragon has written a snippet that you can build upon, see
How to get size of all files in a directory

mitrmkar 1,056 Posting Virtuoso

the call stack has following values.
fwrite(const void * 0x0012ee5c, unsigned int 0x00000001, unsigned int 0x00001000, _iobuf * 0xffffffff) line 105 + 3 bytes

The last parameter for fwrite() has an invalid value (0xffffffff).

Make sure that you succeed in opening the file properly (using fopen()), like so ..

FILE * fp = fopen("my_file.txt", "w");
if(fp != NULL)
{
  /* Managed to open it, now write ... */
  fwrite(..., fp);
}

PS. Why is your text all in bold?

mitrmkar 1,056 Posting Virtuoso

Edit: Allow me to change my earlier comment so no one else gets confused. It is Number of characters MINUS the Null.

Sorry, but you are not right about it - please start believing in what people are saying.

size_t strlen(const char *s);

The strlen function computes the length of the string pointed to by s.

Returns
The strlen function returns the number of characters that precede the terminating null character.

Then consider the following ..

// 11 chars is NOT enough to hold the string "Hello World"
char st[11]="Hello World";

This line compiled with g++, results in an error:

main.cpp:3: error: initializer-string for array of chars is too long

Isn't your compiler saying anything?

mitrmkar 1,056 Posting Virtuoso

ends with a send/don't send message in windows

OK, that's a crash.

I will add some exceptions.

If you mean that you'll be using a C++ try/catch construct - that will not work. You would instead need to resort to structured exception handling (SEH).

Anyway, if the problems persist, perhaps consider posting the code at some later time.

mitrmkar 1,056 Posting Virtuoso

You can put whatever you want in main

Actually definitely not, I suggested you to post the complete code to see what you are actually doing with these functions.

the location the cursor goes to is almost random(or close to the location it should go to)

SetCursorPos/GetCursorPos are not guaranteed to succeed, so you could check their return values. If you read the function documentation, you'll note that the OS might step in and do some adjustments.

It will crash

What do you mean by crash?

mitrmkar 1,056 Posting Virtuoso

There is still a problem with the wind function though.

You might post the complete code (including main()).

mitrmkar 1,056 Posting Virtuoso

Do either of you have any recommendations as to a good free resource compiler?

Just in case you misread/misunderstood my suggestion, if you already haven't, then search the web for free resource editors. In other words, get an editor with which to create the GUI, instead of writing the .rc files manually.

mitrmkar 1,056 Posting Virtuoso

What does -Wall and -pedantic options stand for?
And also as I am new to this system can you please refer me a link where I can learn more about these options?

See http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#Warning-Options

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

I get an error when I put cout as a parameter.

Using cout as a parameter is OK - that's not the error.

Looking at the error message, it seems that you don't have written code for default constructor of class Customer .

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

i can't tell which part of my code is faulty as VC++ points me to this code from <xlocale>

At that point, open the Call Stack window (Debug / Windows / Call Stack) - likely you'll be able to step into your own code to see the offending line.

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

it only outputs one file( but it prints three filenames)

You want to do file.close() after you've written to a file.

mitrmkar 1,056 Posting Virtuoso

i should have known that count doesnt have any value until its assigned :?

Hmm, you made it sound as if the variable would have vanished into thin air :|
Certainly it has a value - depending on the compiler/settings, the value may be random garbage or it may have a predefined value, intended to aim in spotting uninitialized variables. But at any rate, remember to initialize your variables - it's undefined behaviour to end up using uninitialized variables.

mitrmkar 1,056 Posting Virtuoso

Would it help if i made a collectable class?

Errm, I think you need to figure out what you want to achieve - from the ground up.
If you are practising inheritance/pointers - perhaps find some basic tutorials.

mitrmkar 1,056 Posting Virtuoso

There is no mention of what a Collectable represents.
Then it looks like your classes need to be inheriting from Collectable in order for the allocations/assignments to work.

mitrmkar 1,056 Posting Virtuoso

i did this and it outputs only 1 file with the file name in it but i would like to output 3 so what is breaking the check ?

You must initialize count to a value of your choice. It is NOT initialized to zero by your compiler.

mitrmkar 1,056 Posting Virtuoso

It's throwing #234 - More data is available.

Alright, this is progress.

See RegQueryValueEx documentation about its last argument ( LPDWORD lpcbData ).

Since you are passing in the buffer rgValue , the size1 needs to be initialized to the sizeof(rgValue) before calling RegQueryValueEx() .

mitrmkar 1,056 Posting Virtuoso

Thinking of it, I'm not 100% sure whether the Reg* routines set the error state (returned by GetLastError() ). So, modify the code so that you get the return value from these Reg* calls. That would be along the lines of ..

...
LONG lResult = RegQueryValueEx(...);
if(lResult == ERROR_SUCCESS)
{
  lResult = RegQueryValueEx(...);
   ...

If the return value is non-zero, it will be a system error code.

mitrmkar 1,056 Posting Virtuoso

That is weird behaviour, see what GetLastError() tells you.

mitrmkar 1,056 Posting Virtuoso

Compiler Error C2259

>> I cannot see why i am getting them..
For future reference, it's better to post the offending code along with the error messages.

mitrmkar 1,056 Posting Virtuoso

I am using Dev-C++ 4.9.9.2 and no it doesn't give any warning or error message at all.

Dev-C++ is an IDE, not a compiler. You are probably using g++ to compile your code.
Find a way to pass the -Wall option to your compiler, it enables most of the warnings. To see an outline of g++ warning options that you can use, do g++.exe --help=warnings on the command line.

They ran successfully but the output is strange and long ...

Yes, strange because you operated through a zero-sized array.

I don't know what std::vector<Trader> is. Can you explain? What function & how does it work?

std::vector would be your dynamic array of Trade objects. A vector grows (and optionally shrinks) dynamically as needed - a handy feature.
See std::vector.

I already put the specific size of array shown below:

No, the array needs to be declared with a compile-time-constant size.
I meant something along the lines of this ..

struct Trade
{
  ...
};

struct Auctioneer
{
  static const int _traders_max = 123;

  // 123 Trade objects allocated for every instance of
  // class Auctioneer
  Trade array[_traders_max];
};
mitrmkar 1,056 Posting Virtuoso

Which compiler are you using? Isn't it giving any warnings?

The array is a zero-sized array, you want to specify a reasonable size (a compile time constant) for it, in order to use it. Alternatively, perhaps use std::vector<Trader> .

mitrmkar 1,056 Posting Virtuoso

i keep getting :

-on line 7(i.e vector<Bid> BidList (20);) : error 7 expected `;' before '(' token
-and in simulator:20 `BidList' undeclared (first use this function)

The compiler does not have a clue about what a 'Bid' is at line 7.
You might swap the order of the classes, like so ..

/////////////////////////
// First, class Bid
/////////////////////////
class Bid
{
private:

   int bidID, quantity, price, traderid;
   char tradertype;
public:
   static int BidID;
   Bid ( int tid, char ttype, int p , int q ) : traderid ( tid ), tradertype ( ttype ), quantity ( p ), price ( q )
   {
      bidID = Bid::BidID++;
   }

... etc

/////////////////////////
// Then, class Simulator
/////////////////////////

class Simulator 
{

// Now able to use Bid here ...
vector<Bid> BidList (20);

public:
  
   void run();
   void match();
};

void Simulator::run() 
{
... etc
mitrmkar 1,056 Posting Virtuoso

Just started using Code::Blocks last night, after using VS2008, and didn't get a chance to thumb through the options. I REALLY prefer Code::Block over VS2008.

If you will be using gcc/g++, you can find the on-line documentation -> http://gcc.gnu.org/onlinedocs/

Pick the one that matches your GCC version ( g++.exe -v ).

PS. Don't throw away VS 2008, it may come in handy when seriously debugging something.

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

First, open
http://www.daniweb.com/forums/forum16.html
and there, click the area where it reads; "Databases Category (Click to show forums)"
I bet you'll manage to take it from there ...

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

The page
http://www.daniweb.com/forums/misc-explaincode.html
is not displaying at least for me.

mitrmkar 1,056 Posting Virtuoso

Please use code tags. Wrap all your code inside the code tags, like ..

[code]

your code here

[/code]

You still have ~15 minutes to edit your post.

mitrmkar 1,056 Posting Virtuoso

Since this thread's title is "How to Get User Input from console -- safely.", I think it's appropriate to point out a little thing. Namely, in the Aia's version, decrementing size before entering the for-loop is a recipe for buffer overflow if size 's initial value (for whatever reason) is zero.
So, to be on safer side ..

size_t obtainput (char *orig, size_t size)
{
    size_t i = 0;
    size_t  total = 0;
	
    /* Safety check ... */
    if(size == 0)
        return size;

    --size;
...
tux4life commented: Excellent catch! +8
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

I'd bet that it happens due to an uncaught exception of type digits . Hint: there is something wrong at line #72.

[EDIT]
Isn't your compiler giving a warning of any kind, have you checked?

Note that I'm assuming that you are actually calling the string_to_int() function.

mitrmkar 1,056 Posting Virtuoso

>> The code snippet does not compile with Dev-C++ 4.9.9.2. The error messages look like this:
>> [Linker error] undefined reference to 'CreatePen@12'
>> [Linker error] undefined reference to 'SelectObject@8'

See the code snippet comments, there it says;

  • with Dev-C++ link libgdi32.a via Project>>Project Options>>Parameters>>Add Lib>>libgdi32.a
mitrmkar 1,056 Posting Virtuoso

This is somewhat a guessing game without the exact code. But I'd suggest that you open the header file and scroll down to the very bottom of it, just to see that there absolutely isn't anything after the semicolon that ends the class declaration.