ArkM 1,090 Postaholic

Yet another advice. I have used Doxygen documentation system at initial stage of troubles with (as usually) undocumented third-party projects (from 50000 to 300000 lines in C and/or C++, hundreds of files). You may get a very visible web-oriented report with collaboration and inheritance diagrams, file dependencies, call trees, etc.
Of course, it is a static code analysis product but I think it's a very useful bird's-eye view to others' code chaos.
http://www.stack.nl/~dimitri/doxygen/

ArkM 1,090 Postaholic

Well, and what do you want to do with this 5-years old slops?
Better think then implement the proper solution from the scratch.

ArkM 1,090 Postaholic

Can you present the original specification of the "remove chars" stuff (not this wittingly incorrect implementation)?

ArkM 1,090 Postaholic

See, for example: http://en.wikipedia.org/wiki/Virtual_inheritance
So class className is a suitable player for "diamond" inheritance.

ArkM 1,090 Postaholic

I have posted you at least two links to much more simpler than GNU MP bigint C++ libraries:
http://www.daniweb.com/forums/thread190103.html
Why you ignore this fact?

ArkM 1,090 Postaholic

Use binary output (write member function) to save/get an array. It takes less than 1 second for ~1 million array elements (and probably ~1 milliseconds to populate this array as Salem said).

ArkM 1,090 Postaholic

wow... hahaha, well at least my class was ok! Does

Log(filename)

have any use? Why is it not a compiler error?
Thanks for finding that ridiculous bug :)

Some immodest question to OP:
Are you sure that this OP problem is not solved yet?
;)

ArkM 1,090 Postaholic

>it does have all string type object...
std::string objects contain pointers to text but not a text per se. So a pointer to std::string object never refers to a text.
Read about object serialization in C++: http://www.parashift.com/c++-faq-lite/serialization.html

>i can send you the whole software if you want...
Thank you. May be, some other time...

ArkM 1,090 Postaholic

Compiler error? Why?

expression_statement:: expression;
expression:: value | ...
value:: constructor_call | ...

It's a well-formed expression statement.
May be this constructor has drastic side effects... May be all my program code is concentrated in this constructor ;)

ArkM 1,090 Postaholic
Log(LogFilename);

You have wrote Log constructor in the expression-statement: create an object then discard it - redirect the stream then come back - i.e. do nothing ;).
Try this (what desired):

Log anyVarName(LogFilename);
ArkM 1,090 Postaholic

ios::app flag means append or write at the end of file. Nobody can append anything to input file (and you? ).
it wont write is not a fact, it's a lyrics. Imagine that file.open("LOGIN.DAT") can't open file (wrong path, for example). You didn't test file state after open call. Suppose your p1 object is (or has) a std::string type object. You can't write string text with this barbaric reinterpret_cast approach...
An so on...

Diagnosis: insufficient info.

ArkM 1,090 Postaholic
int linecnt;

for (linecnt=0; getline(inData2,line); linecnt++) {

}
if (linecnt == 0) {
   // no lines report...
   return; // return value - return false, for example
}

Now if (!line) is a wrong and senseless construct. No operator!() for std::string. You have a line (may be empty) in the loop body (see your own loop condition ;))...

It's not the best method to exit() from C++ functions: local variables destructors are not called in that case. Better avoid C++ program termination with exit().

ArkM 1,090 Postaholic

Where are p1 and per1 vars class definitions?
Why ios::app for input stream?
"stop working" - what is it?
Can you clearly describe your problem?

ArkM 1,090 Postaholic

Alas, it IS an error:

for (size_t i = 1; i < Data.size(); i++) {
    ... // the last loop: i = Data.size()-1
    v2 = Data[i+1][9]; // i+1 == Data.size()
    // No such element in the Data vector!!!
    ...
}

;)

ArkM 1,090 Postaholic

That's it:

v2 = Data[ i+1 ][ 9 ];

Obvious subscript error i+1 on the last element ;)

Next time use code tag with the language specifier:
[code=cplusplus] source

[/code]
DaniWeb engine shows source line numbers in that case...

ArkM 1,090 Postaholic

>...then you're working for the NSA...
That's it! (see my the 1st post in the thread above ;).

"Unpredictable" or "non-reproducible" sequences (it's not the same as "random") are used for generating of forgery-resistant keys in cryptography (as usually with special external devices). In actual fact an ordinar desktop computer can generate some kind of (low-quality) "unpredictable" sequences. However it's not so simple work.

I think for non-critical applications (like OP;)) no need in methods like soundtrecks and other exotics. Get keystrokes trace (with millisecond oprecision intervals), calc SHA1 digest of this trace - that's 160 "unpredictable" bytes. Take into account that OP did not define any "randomness" criteria so any one solution is not worse that any others ;)...

Let me repeat myself: more advanced methods are a valued know-how and Daniweb is not the best place to discuss them ;)...

tux4life commented: The best method I've seen in this thread :) ! Very very good :P !!! +3
ArkM 1,090 Postaholic

Alas, it's an absolutely incorrect algorithm. Look at your select condition:

if (check_array[t] == array_element) // if match is found
{ 
    flag = 1;
    break;
}

In other words you make selection if and only if you have selected the element already!
Quite the contrary, make selection if and only if the element was not selected yet:

if (check_array[array_element] == -1) {
    check_array[array_element] = array_element]; // or what else but -1
    cout << ...
    chosen_words++;
}

No need in the inner loop and flag var at all.
Apropos, better use bool array with all false elements initially.

ArkM 1,090 Postaholic

The OP problem was not specified. I want true random numbers - what did OP mean by that? There are lots of possible answers. May be SHA1 digest of anything is a good solution (of undefined problem;)), it's a question ...

ArkM 1,090 Postaholic

Ok so I want to create some code which can generate a random number from a
1. Music file
2. A microphone
PLEASE is their anyway i can do this

It's possible but you need non-trivial theory and lots of experiments. As usually results of these works were a very protected (sometimes patented or/and top secret) know-how(s)...
It's the other story why...
The key point is: what's (and why) a distribution of your home-made generated sequence? If you don't know the answer then it's not a true random number generator...

ArkM 1,090 Postaholic

#3: Yes, I can: for example, return "?" or "*" or an empty string or what else (clearly documented) to indicate error conditions.

#4: Well, where is the requirement: we need at least one static variable in the code? ;)

#6: Reread my post again, it's about values, not bases: value == 0 => bufsize == 1; value 1..9 => bufsize == 2 (see while statement in the line #19).

#7: You must return exactly the same pointer value which you got from the operator new (line #27) otherwise it's impossible to free the memory obtained "on behalf of the caller". It's exactly your case: your itoa(0,10) returns buf+1 address. It seems you didn't test your function at all. It's a severe error but I can't see the correspondent requirement: the program must return the pointer value which is unacceptable for dynamically allocated buffer deletion ;)

#8: OK, look at the line 7. The simplest way to change sign: v = -v; The worst one (the most expensive): v *= -1; ;)

ArkM 1,090 Postaholic

>What do you think of my implementation though?
I don't like both implementations (your and mine).

I'm considering allocating the space on behalf of the caller as a bad practice (except malloc in C, but no need in malloc in C++ ):
1. It's annoying and error-prone to deallocate returned memory on behalf of the callee. It's a narrow pedantry to count this tiny buffer size in relatively expensive (operator divide) loop. As usually, there is some minimal size of an allocated heap chunk in C++ implementations (16 bytes or ever more) so you can't save actual memory expenses.
Another defects:
2. The RTL itoa allows bases in the range 2..36 however you provide 8, 10 and 16 only. Why?
3. It's a bad practice to print messages in low level utility functions (see line #21). For example, it's impossible to use your function in GDI applications (no stdout in this environment).
4. Why buf variable has a static duration? Now your function is not reenterable, we can't use it in multi-threaded environments.
5. No proper argument check out: what happens if base == 0? Why the only arg check inserted in line #20 but we are trying to calculate anything for unacceptable base value in lines 4..18?
6. Why bufsize == 1 for value == 0 but it's equal to 2 for values from 1 to 9?
7. The last but not the least: your implementation returns wrong pointer …

ArkM 1,090 Postaholic

~0.5 years ago, not so far, far away (on DaniWeb forum):
http://www.daniweb.com/forums/thread148080.html
;)

ArkM 1,090 Postaholic
void name() { std::cout << "It's me, Xamas\n"; }
inline void anothername() { name(); }
void ((*yetanothername)()) = name;
void tryThis()
{
    name();
    anothername();
    yetanothername();
}

;)

ArkM 1,090 Postaholic
ofile.open(file.c_str());
...
ofile.close(); // function call!

In the current C++ Standard fstream::open member function wants const char* argument only, not const std::string& .

ArkM 1,090 Postaholic

That was just a logical mistake from me :P ...

Remember classics: It's not a mistake: it's a feature...

ArkM 1,090 Postaholic

ofstream infile; // create a new output stream infile.open ("[I]yourfile[/I]", fstream::app); // open the file for appending

Output stream named infile... That's cool! ;)

tux4life commented: You're absolutely right, logical mistake from me, but the code is still working :P +2
ArkM 1,090 Postaholic
while("sMessage[x]"){

Why quotes?! ;)
It's a loop forever: while (pointer to string literal != 0). It never is null...

jephthah commented: good catch +8
Salem commented: Indeed +29
ArkM 1,090 Postaholic

May be (I'm not sure) the problem is:

The variant types VT_DISPATCH, VT_UNKNOWN, and VT_BSTR are pointers, and do not require another level of indirection.

If the 3rd argument of SafeArrayPutElement call has BSTR type, no need in an address operator in the call (?)...

ArkM 1,090 Postaholic
myfile.open(filename,ios::app);
ArkM 1,090 Postaholic

I don't understand... Is there a problem with ctime?

No problems with ctime. There is a problem with OP requirements:

I need a solution. I have a uint32_t variable say var1. I need to store current time value in this variable,,,

ArkM 1,090 Postaholic

Try DISLIN:
http://www.mps.mpg.de/dislin/
It's free for non-commercial use.

ArkM 1,090 Postaholic

Regrettably, there is no a little thing in <ctime>: guarantee of 32-bit integer time type.
The time_t type is an arithmetic type capable of representing times - that's all...

ArkM 1,090 Postaholic
inline
unsigned getMin(uint32_t t) {
    return (t/60)%60;
}
inline 
unsigned getHour(uint32_t t) {
    return t%3600;
}
inline
unsigned getSec(uint32_t t) {
    return t%60;
}
inline
uint32_t makeTimeOfDay(unsigned h, unsigned m, unsigned s = 0) {
    return s + 60*m + 3600*h;
}
inline // returns interval abs value
uint32_t diffTime(uint32_t t0, uint32_t t1) {
    return t0 > t1? t0 - t1: t1 - t0;
}
/// Local time of day in seconds since midnight
uint32_t getLocalTimeOfDay()
{
    time_t t(time(0));
    tm* p = ::localtime(&t);
    return makeTimeOfDay(p->tm_hour,p->tm_min,p->tm_sec);
}
uint32_t getUtcTimeOfDay()
{
    time_t t(time(0));
    tm* p = ::gmtime(&t);
    return makeTimeOfDay(p->tm_hour,p->tm_min,p->tm_sec);
}
ArkM 1,090 Postaholic

Probably the simplest way to go:

#include "../projectBfolder/B.h"

or add the project B folder to include paths list of the project A. How to do it depends on your IDE, of course...

ArkM 1,090 Postaholic

Avoid listening to programming advice that says you absolutely must or must not do something.

Good metaprogramming advice ;)
Never forget to declare C++ variables before...
To ignore or not to ignore? ;)
Is it an advice or a requirement? Where is the border?...

ArkM 1,090 Postaholic

Cascades of monstrous data moving... have you ever heard about operator= in C++?

clients[i] = clients[i+1];

instead of awful (quote):

clients[i].name=clients[i+1].name;
clients[i].table_number=clients[i+1].table_number;
clients[i].type=clients[i+1].type;
clients[i].bill=clients[i+1].bill;
clients[i].order.soup=clients[i+1].order.soup;
clients[i].order.salad=clients[i+1].order.salad;
clients[i].order.beefsteak=clients[i+1].order.beefsteak;
clients[i].order.pizza=clients[i+1].order.pizza;
clients[i].order.pancake=clients[i+1].order.pancake;
clients[i].order.cake=clients[i+1].order.cake;
clients[i].order.soda=clients[i+1].order.soda; 
clients[i].order.whisky=clients[i+1].order.whisky;

That famous system("pause") after prompt "Try again" ???
It seems no once input result check in the program (it's so simple)

if (!(cin >> choice)) { // not a number entered
   cout << "Not a number, try again...\n";
   cin.clear();
   cin.ignore(1000,'\n');
   continue;
}

Death sentence: there are gotos in switch statements...

I can't imagine that this program is capable to do anything...

Next time use code tag properly:
[code=cplusplus] sources

[/code]

ArkM 1,090 Postaholic

About the second point. I think that error message printing on too low level is a very harmful practice. In that case we have a chance to get a bucket of messages on a single failure. Besides that low level routines can't print sensible messages because they have no wide context info. For example, the only sqrt calculation routine message is "Alas, my argument is lesser than zero" - well, it can't be helped. Now you can't use this damned routine in GUI codes - std::cerr object does not exist there...

I'm not sure that exception on open file operation failed is a good idea (of course, it depends on developed system architecture). As usually we don't open files in every line of code. It's not so hard to check return code from loadFile routine (file is loaded or not loaded). Exceptions are suitable for extraordinary, as usually fatal (global) events. Yet another example of local failures where exceptions are suitable: get next token calls in syntax parsers (or get next CSV field in data importers). We can avoid annoying return code checks if getnexttoken will raise an exception if no token or bad token detected. We'll catch this exception locally, make recovery, print sensible message etc.

Clockowl commented: Clear explanation. +1
ArkM 1,090 Postaholic

Think again about exception handling pragmatics. You raise exception deep inside a function call stack when a (relatively) low level function does not know what to do in this case or it can't inform user because it has no access to user interface (console?.. windows?.. or it's a service w/o UI? ). Another example: your function detected i/o error and can't continue but this program user has very confused notions about files, databases and other computer rattles. Let my boss(es) decides what to do and how to inform my user in this case: that's exception raising logics.

On the one hand you can react to possible failures on the right level, on the other hand you can improve your code: no need in awkward "if return code is OK" cascades now. To raise an exception is a natural method to react on failures in class constructors (they can't inform about failures via return codes).

That's why I can't understand your question: There's no way of catching the exception "going on" ? I can only check whether there's one (from anywhere in the code?), but not which one? You can catch different classes of exceptions by different catch clauses:

try {
  ...simple and clear mainstream code
}
catch (can_t_open& ex) {
  ...
}
catch (can_t_close& ex) {
  ...
}
catch (we_re_done_for& ex) {
  ...
}
catch (...) // other troubles
  ...
}

Some remarks on your example code. The loadFile function returns boolean value. Evidently it's a classical …

ArkM 1,090 Postaholic

Of course, you need try-catch construct to intercept exceptions. Nobody can call what() member function without alive (raised) exception object: what() of ... what?

What's a problem?

int main()
{
  int rc = 0;
  // prologue
  try {
    // processing
  }
  catch (runtime_error& ups) {
    cerr << ups.what() << ...
    rc = 1;
  }
  ... other selected exception handlers
  catch (...) { // (total crash ;)
    cerr << "*** unknown exception..." ...
    rc = 2;
  }
  // epilogue
  return rc;
}
ArkM 1,090 Postaholic

http://www.cs.utsa.edu/~dj/ut/utsa/cs3343/lecture7.html
Yes, common priority queue implementations are based on heap data structure founded on a linear (as usually, in array) representation of a tree...
;)

ArkM 1,090 Postaholic

Well I would appreciate you backing up a statement like that!
There are 2 threads here. One reads and writes (ie an addition), the other just reads. Two threads can indeed access the same memory quite happily (ok there might be some exceptions for custom embedded systems, but we're talking general purpose computers here). You have to remember that the operations in separate threads are not actually happening simultaneously, they are sequential at the hardware level and will not generate bad/corrupted data.
The write operation is atomic, you can't get half a write operation, so the read from the other thread will either get the value before or after the write. In this case it doesn't matter which it gets.
Of course, you do need to be aware of the operations you perform. Reading/writing a database in this way would not necessarily be atomic and possibly not safe.

>You have to remember that the operations in separate threads are not actually happening simultaneously
It's a wrong statement even for home desktop compiters with multicore processors.
>...and will not generate bad/corrupted data
It's a wrong statetement, especially referred to compound objects.
>The write operation is atomic, you can't get half a write operation...
It's a wrong statement, especially for string data, but for compound objects too. As usually, regular microprocessors provide atomic write operations only for 32-bit aligned words.
>In this case it doesn't matter which it gets
It's a wrong …

ArkM 1,090 Postaholic

Try GetVersionEx Windows API function.
See MSDN article(s): http://msdn.microsoft.com/en-us/library/ms724451(VS.85).aspx

ArkM 1,090 Postaholic

1. All matrices are 2D arrays by definition ;)
2. As usually, matrix classes provide matrix oriented operations (transpose, invert, matrix arithmetics etc. Are you sure that you need all these features for simple game navigation (can't imagine what's a beast)?
3. May be better try to present some of a lot of problems with the one you created? A simple grid structure has a lot of simplest implementations in C++...
4. Google (or this forum) search gets tons of links on 2D arrays/matrices in C++...

ArkM 1,090 Postaholic

That's because there are xd[0] and xd[1] only elements in the array int xd[2] ;)...

ArkM 1,090 Postaholic

The second case is not a declaration of Link<int> instance (object), that's why it was "compiled fine". It's a prototype of a function (never called) without parameters returned Link<int> object.

Most of C++ compilers can't process programs with separated template definition and implementation. Move Link template constructor from list.cpp to list.h.
Now correct the 3rd case (wrong delete *test3 ). It's not a linker error ;)

All done.

ArkM 1,090 Postaholic

It's so simple: if you want to process a Type array argument then declare the correspondent parameter as Type a[] or Type* a . Now access this array elements as a[i] .

An array argument always passed as a pointer to the first array element (an array index sequence started from 0, so it's a[0] . That's why you can declare array parameter as a pointer.

If you don't want to change this array elements then better declare the parameter as const Type a[] or const Type* . It's exactly your case in show... functions.

Yet another good advice: never start coding until you understand so basic language concepts, otherwise it looks like you young pilot try to become familiar with landing procedures after take off only (via Internet link aboard ;)).

ArkM 1,090 Postaholic

Better post a code where macro doesn't seem to work.
More accurate this substitution definition is

#define stack_empty(x) (*(x) == 0)

However it's a strange parameter type stack**. It has two indirections - why?

If you have a modern (standard-compliant) compiler better use inline keyword...

ArkM 1,090 Postaholic

Yet another defects (obvious):
1. The comparelist function does not compare lists, it compare two integers (now). Moreover, the 3rd parameter of equal semantically defines "compare nodes" function! The natural 3rd parameter prototype is int(*p_cmp_f)(const int*,const int*) or even int(*p_cmp_f)(const NODE*,const NODE*).
2. Extremely ineffective function equal implementation. For example, two last ifs are exactly the same as:

if (empty_list(L1) || empty_list(L2)) return 0;

No need in recursion: the simplest loop over two list is more clear and effective.

Apropos, no need in this clumsy (*p_cmp_f)(...) call. Do it in a simple and clear manner:

p_cmp_f(...)
ArkM 1,090 Postaholic
  1. Operator priorities: a<<2 + a treated as a << (2+a).
  2. Undefined result; side effect of ++ operators and undefined order of argument list evaluation, cases <2>+=pow(2,2), <3>+=pow(2,3) and others are possible...
  3. It's only the union U type (not a member) declaration in struct s definition body.
ArkM 1,090 Postaholic

Can you explain why you have invented so strange manner to die for your top secret application? ;)...