ArkM 1,090 Postaholic

The template generation does not pay attention to executable statements in the template definition. The if (n > 0) does not prevent recursive template bootstapping for GetNRands<0>, GetNRands<-1> and so on. It's pity that VC++ can't detect this "instantiate forever" recursion.

To break this recursion you may define this template specialization for n = 0:

template <> 
struct GetNRands<0> {
static void fillVector( set<int>& v, int max ){}
};

It's a template generation analogue of sacramental if (n == 0) return 1; in famous (and the same absurd) recursive factorial ;)

Alex Edwards commented: Absolutely! O_O +5
ArkM 1,090 Postaholic

I have never seen before so funny "definitions" of a "unix timestamp" data type and a "system time" representation: ;)

unix time stamp is like = 1227806311
the same system time stamp is = 27/11/2008 HR MIN SEC

Well, try to adopt this code:

/* UnixTime is unspecified unix time stamp type.
     * Define it before compilation, for example:
     * typedef time_t UnixTime;
     *  or
     * typedef long int UnixTime;
     */
    UnixTime ut;  /* Unix timestamp to be converted */

    time_t thist; /* This system timestamp value */
    struct tm* ptm;
    char mysyst[20] = "\?"; /* for "sys time" */
    const char* fmt = "%d/%m/%Y %H %M %S"; /* sys?time */
    /* C Standard does not specify what's time_t epoch */
    time_t uepoch; /* Unix epoch in this system time_t */
    struct tm tmepoch;
    /* Prepare unix time epoch on this system */
    memset(&tmepoch,0,sizeof tmepoch);
    tmepoch.tm_year = 1970 - 1900;
    tmepoch.tm_mon = 1 - 1;
    tmepoch.tm_mday = 1;
    tmepoch.tm_hour = 0;
    tmepoch.tm_min = 0;
    tmepoch.tm_sec = 0;
    uepoch = mktime(&tmepoch); /* this system unix epoch */
    /* Recalculate unix time to this system time_t */
    thist = (time_t)ut - uepoch;
    ptm = gmtime(&thist); 
    if (ptm && strftime(mysyst,sizeof mysyst,fmt,ptm))
        printf("%s\n",mysyst);
ArkM 1,090 Postaholic

Yet another remark.

...
Really, how often do you really mean to have a loop be infinite? When you see either of those constructs, that means you gotta dig through the code to find where the writer is busting out with a break statement. The beginning of kludgy code. The loop statement should tell you why the loop ends.
...

Loop forever pattern is a natural construct in operational/embedded systems and servers/services programming. Besides that there is "Loop and Half" pattern:

loop
    prepare (read, compute etc)
    if (condition) break;
    process
end loop

So the last sentence above with "should" looks at least opened to questions. ;)
Apropos, let's remember: the C and C++ for loop is not a counter-controlled loop at all. Its syntax/semantics pattern is:

for ([prelude]; [condition | true]; [interlude])
    body
ArkM 1,090 Postaholic

Can you explain what is meant by "unix timestamp" and (mainly) "system timestamp"?

ArkM 1,090 Postaholic

911: http://www.daniweb.com/forums/announcement8-2.html
Sample code needed? Google is your friend!..

ArkM 1,090 Postaholic

for (;;) { /* Of course, tastes differ. Some remarks.

The for loop is not (only) "loop a specific number of times" for me (quite the contrary - remember containers traversal pattern). It's the most generic loop construct in C and C++. So for(;;) construct gives (me) a brief and clear (and stylistic neutral) demonstration of "loop forever" programmer's intension.

On the other hand I don't like constructs if (constant-expression) or while (constant-expression) . As usually, they are erroneous or looked as truism. The while (condition) construct means (for me) literally "loop while computed condition is true" - but it's a very strange phrase "loop while constant true is true"... */} ;)

ArkM 1,090 Postaholic

Have you ever seen the compiler message? It's AdjacencyMatrix constructor was not defined!

chunalt787 commented: Good quick answer thanks so much +1
ArkM 1,090 Postaholic

result is a local variable, which is destroyed when the functions ends. So a garbage value is destroyed. The best solution is to do what is said by the poster above.

If you need to work with pointers you can do this:

double* treble(double data)
{
	double result = 0.0;
	result = 3.0*data;
	return new result;
}

now result isn't destroyed and a pointer to it is returned. However, this memory must be freed manually.

delete ptr;

No errors means even number of errors ;)
Incorrect example and wrong explanation (result always "destroyed": it's local automatic variable). Right "solution":

double* treble(double data) { return new double(3.0*data); } Never, ever do that. It's totally senseless and a very dangerous programming style.[code=c++]
double* treble(double data)
{
return new double(3.0*data);
}
Never, ever do that. It's totally senseless and a very dangerous programming style.

ArkM 1,090 Postaholic

Reread the get member function specification more carefully.
If cin.get(b,2) can't obtain the next char from the cin, it sets failbit for cin. When the cin stream is in failed state, no more operations performed until you clear the cin state (by cin.clear(), for example). Now cin.ignore and cin>>... ignored - that's why the program performs loop forever.

Counter-question: what for start label and goto?

for (;;) { // loop forever: it's a clear and honest construct
...
}
// or (I don't like this)
while (true) { // longer and precious
...
}
ArkM 1,090 Postaholic

Windows API HWND type is defined as void*, not struct HWND__ * . Obviously pgui->getDrawArea() returns another type (for example, MFC Cwnd is a simple HWND wrapper).

ArkM 1,090 Postaholic

May be better stop this farce with rainbow coloured messages? It seems the (semi)professional forum is an area of communications but not a self-expresson...

Have you ever seen the strtok C standard library function?

ArkM 1,090 Postaholic

Are you sure that you really understand the difference between "declare" and "define" in C++? I think jencas was right and you don't DEFINE that constructor.

ArkM 1,090 Postaholic

I found what I was looking for on the DarkGDK forum but does anyone know where to view a map of the keyboard with the numbers that correspond to the keys (ex: 71=num pad '8')?

Have you ever heard about Google search? ;)
http://www.barcodeman.com/altek/mule/scandoc.php

ArkM 1,090 Postaholic

I'm more of a newb but feeling cocky as always:

Don't AVOID compiler specific functions, but be sure to find a cross-compiler way to do it as well, as in: find it, use it a couple of time, memorize it.

However, I think it's a definite plus if you also know compiler specific tweaks.

Well, repeat your admonitions when you will port 500000 LOC with compiler-specific calls in the new environment ;)...

ArkM 1,090 Postaholic

As far as I know Dark GDK application HAS NO CONSOLE at all. If so you can't use conio.h or Windows API ReadConsole stuff. It's GUI application. Dark GDK has its own keyboard event handling and corresponding API. You can find more info in DarkGDK docs or ask Dark GDK guru on Dark GDK forum.
May be I'm wrong?..

ArkM 1,090 Postaholic

Is it so hard job to correct obvious errors: you get compiler messages on wrong function arguments: fread and fwrite want POINTERS to target/source data areas (&d - not d, &b - not b))!

Use code tag properly:
[code=c] source

[/code]

Never use dangerous gets function: it does not check target buffer size. Use fgets instead of gets:

fgets(fn,sizeof fn,sdtin);

With gets you program crashed if the file name length is greater than 49.

Don't forget to append carriage return:

printf("\nFile saved\n");

Avoid using of non-standard function flushall().

Whilliam commented: best answer +1
ArkM 1,090 Postaholic

Better use

std::ifstream file(...);
std::string line;
...
while (getline(file,line)) {
...
}
if (file.fail()) { // i/o error occured
...
}
ArkM 1,090 Postaholic

If you need fast sorting, think about another approach: keep your data sorted - for example, maintain balanced tree with nodes pointing to data structures.

ArkM 1,090 Postaholic

Probably the best place for Dark GDK question is Dark GDK community forum...
I can't imagine what's a relation between #include <conio.h> in your modules and errors in Dark GDK files...

ArkM 1,090 Postaholic

You declare these member functions but forgot to define them.
Probably, you define functions with such names without class name prefix, for example:

double GetRandomNumber() // Ordinar function
{ // does not bear a relation to the class 
    ...
} // You need
double RandomVariableGenerator::GetRandomNumber()
{
    ...
}

Don't use C-style declaration name(void) for a function w/o parameters.

ArkM 1,090 Postaholic

1. Use code tags correctly:
[code=c] source

[/code]
2. It's not a declaration only (with extern) for global variable: it's a very strange definition (with enormous macros currentpacketbeingsampled? or with macros xdata? ):

char xdata currentpacketbeingsampled;

Never add definitions (except classes and templates in C++) in header files.
Never use so strange syntax with macros.

ArkM 1,090 Postaholic

Some additions.
I think a radix sort is not a suitable method to sort array of structures with sort key fields. You need a lots of additional memory and unnatural code modifications.

Probably the simplest way to adopt common sort codes (usually published with int array parameter) for structures sorting in C++ is to define a proper compare operator.

For example, let's adopt sort codes from the excellent tutorial:
http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_sorting.aspx
Get selection and Shell sort algorithmes. The selection sort is a good method for a fast compare operation but relatively slow data movement case (typical for struct sorting). However it's a slow method suitable for short arrays only. That's why the second example is a Shell sort - relatively fast with a very simple implementation.

struct POINT3D { double x, y, z; };

struct Edge { // I don't like all-capital names ;)
    int poly;
    double inv_slope;
    int b;
    POINT3D p1, p2;
};

inline // see compound key handling
bool operator>(const Edge& e1, const Edge& e2) {
    return e1.b > e2.b
        || e1.b == e2.b && e1.poly > e2.poly;
}

void SelectionSort(Edge a[], int n )
{
    int maxi;
    Edge w;

    while (--n > 0) {
        maxi = n;
        for (int i = 0; i < n; ++i)
            if (a[i] > a[maxi])
                maxi = i;
        if (maxi != n) { // swap
            w = a[n];
            a[n] = a[maxi];
            a[maxi] = w;
        }
    }
}

void ShellSort(Edge a[], int n )
{
    int i, …
ArkM 1,090 Postaholic

Your second method is broken -- you forgot isdigit. Your third method is not radical.

Negative values will fail when a lookup table is used to implement the function -- they point in memory outside the lookup table.

#2 Yes, it's annoying misprint ;)
#3 Radical means that it's absolutely implementation-independent method with a very fast instructions generated.
The last remark is a truism.

ArkM 1,090 Postaholic

Some notes about isdigit and non-ascii characters:

The isdigit is a C library function (the C library is a part of C++ library) so let's open the C language standard:

The header <ctype.h> declares several functions useful for classifying and mapping
characters. In all cases the argument is an int, the value of which shall be representable as an unsigned char or shall equal the value of the macro EOF. If the argument has any other value, the behavior is undefined.

So isdigit domain is 0..255 + EOF macros (usually -1). It's well known that char type may be signed or unsigned. If it's signed, all non-ascii char values implicitly converted to negative integers (formally bad values for all isXXX family).
Fortunately it's so simple to cope with the problem in platform-independent manner, for example:

if (isdigit(c&0xFF))    // 1st method
if ((unsigned char)c) // 2nd method
// C++ style radical method #3:
inline bool isDigit(char c) { return c >= '0' && c <= '9'; }

The 3rd method gets the fastest code with a good compiler.

ArkM 1,090 Postaholic

A rather strange loop, see what happens:

while (cardsRemoved<participants)
{
    int r = 0; // r created on every loop, initialized 0
    kanban[r][c]=kanban[r][c]-1; // always [0][c] = [0][c]
    r++; // incremented, but r shall die soon
    cardsRemoved++; // automatic r ended
}

Probably you forgot that the loop body is a block. The r variable is declared in this block. It's created anew with value 0 on every loop. Result: kanban[0][c] decremented while cardsRemoved<participants . Obviously it's not a desired effect.

Regrettably, I have no time to check up more codes at the moment. Correct (trivial correction) this fragment and continue...

ArkM 1,090 Postaholic

After all Dev-C++ is not a compiler, it's frozen IDE (v.5 beta forever) with OLD version of MinGW compiler.
So beautiful zombie ;)...
Code::Blocks is IDE under active developing and support with NEWEST version of MinGW compiler.
Feel the difference...

No MFC in free VC++ 2008 Express, only NET Forms for GUI.

ArkM 1,090 Postaholic

OK. let's start from the beginning. A type is a sum of two things: set of values and set of operators. Consider std::string type. It has two operator + (avoid possible const modifiers):

string + string   // concatenate two strings
string + (char*)  // append a contents referred by 
                  // right pointer operand 
                  // (upto zero byte occured).

No such beast as string::operator + with int type right operand!

Consider char* type operator +. It's the only (avoid all unsigned/short modifiers):

(char*) + int // add right operand value to 
              // the left operand pointer
              // (move pointer forward or backward)

Let's consider the code:

char* p;
p = ....     // p points to char array
p = p + 1;   // p points to the next element
p = p + '1'; // most interesting: '1' converted to int,
             // it's 49 - move p 49 positions forward
p = p + "1"; // error: no operator (char*) + (const char*)

There are (at least) two common ways to get a text (char) representation of int value in your program:

1. Use C library functions (it's a part of C++ library). No string type in C so you must use char arrays only.

char numtxt[32]; // large enough to place any int value
int num = 12345;

sprintf(numtxt,"%d",num); // Ooh, we have "12345" in numtxt
...
string s("Number is ");
s = s + numtxt; // string + (char*) operator used
// or …
ArkM 1,090 Postaholic
int main()
...
    GetNth(first,index); // line #28: undeclared name index

Is it a subtle insult or a total disorder?..

ArkM 1,090 Postaholic

OK, but it's not so good-looking manner (to some extent ) to present this C-like code which I (and anybody else) can't compile w/o numerous errors (mostly undeclared identifiers).

ArkM 1,090 Postaholic

Don't use Dev-C++: the project is frozen
1. VC++ 2008 Express: ~400 Mb (with MSDN Express) + >100Mb Windows SDK:
http://www.microsoft.com/express/download/#webInstall
2. Code::Blocks IDE with MingGW compiler (G++ from gcc family Windows port) -~20 Mb:
http://www.codeblocks.org/downloads/binaries

Both compiler implement (almost) C++ Standard (if you don't use MS .NET VC++ "extensions").

Book: no comments.

ArkM 1,090 Postaholic

Well, but WHAT are your problems?

ArkM 1,090 Postaholic

Fortunately, it's so simple:

std::string s;
    s = "Base ";
    s += "next item. ";
    s += "The end.";
ArkM 1,090 Postaholic

My dev-c++ compiler is telling me that ios::noreplace is not a valid member of std::ios. Why?

Because no ios::noreplace in C++ at all (10 years or more):
http://www.devx.com/tips/Tip/14544

ArkM 1,090 Postaholic
char string[2];
string[0] = function() + '0';
string[1] = '\0';

This seems to work, why? I've googled up a bit but can't figure it out.

I don't know where and what are you googling.
That's a result of my 5-second googling (1st reference in the reply list):
http://irc.essex.ac.uk/www.iota-six.co.uk/c/b1_the_char_data_type.asp
;)

ArkM 1,090 Postaholic

...unsigned short integer is ALWAYS 1 char long

That's wrong statement. The "length" of unsigned short value is sizeof(unsigned short) . The length of char value is ALWAYS 1 by the language definition. Now try to print sizeof(unsigned char) and see what happens.

1. What's array called number type? Show me its declaration.
2. The second snippet is wrong (too ;) ):

cha[2] = (char)1;

Now cha is an array of two chars with element values: { 1, 0 }. But 1 (one) IS NOT a code of one as a printable char! It's '1' - char constant literal. The value of '1' is 49.

Probably, you had never seen char literals. It's strange. I think you can solve the 1st problem as soon as you understand a difference between 1 as integer and '1' as char values...

ArkM 1,090 Postaholic

Don't pursue mirages. Floating point arithmetics is binary, not decimal. Strictly speaking, no such double values as 0.45 or 0.1. Both real numbers are periodical binary fractions but it's impossible to represent infinite series of 0/1 exactly in 64-bit words (more precisely in 53 bits, see http://en.wikipedia.org/wiki/IEEE_754#Basic_formats).

All double values are approximations of correspondent real numbers with precision of ~15-16 decimal digits (all digits, not only fractional part). That's why your test was terminated after 15 loops.

Let we want to get 2 digits of fractional part as integer.

double x = 123.45; // it's ~0.45 (0.4499..X or 0.4500..Y)
int intfp2;
...
double intpart, fractpart;
fractpat = modf(x,&intpart); // fractpart ~= 0.45
fractpart *= 100.0;          // ~45.0
fractpart = floor(fractpart+0.5); // rounding to nearest int
intfp2 = static_cast<int>(fractpart);// == 45

Without addition 0.5 we have a risk to get 44 instead of 45.

Of course, you may use the same method for 1, 3 and so on fractional digits (multiply on 10, 1000 ... ). But you never get more than 15 fractional digits. Don't forget to convert a double value to positive number before split it to integral and fractional parts (use fabs or a simple conditional expression).

ArkM 1,090 Postaholic

Oh, I see: you can't INITIALIZE non-static array member in a class definition with initializer-list! Yes, it's impossible in modern C++.
In actual fact it's not a tragedy, it's discomfort (to some extent). Add initialization code in the class constructor, for example:

class CanDoThat
{
    int array[12];
public: CanDoThat() {
    static int data[12] = { 0,1,2,...11 };
    for (int i = 0; i < 12; ++i)
        array[i] = data[i];
    }

The class constructor initialize class objects. Moreover, really this (or like this) code works for all non-static regular arrays initialized by initializer-list...

ArkM 1,090 Postaholic

Sorry I don't get your meaning. I figure out my mistake after posting.
Now I'm figuring out why I'm unable to declare an array in class like in a struct.
Cause it seems weird for me to declare an array like that.

Why you unable to declare an array in class like in a struct?!
May be you have your own personal C++ language?

ArkM 1,090 Postaholic

What's a problem? Do not declare this static member array as const - that's all.

At first YOU say to compiler that "it's a constant array, don't allow ME to change it" - then cry ;)...

ArkM 1,090 Postaholic

A string literal is a constant value in modern C and C++, so the pointer to it has const char* type (not char* ). The Melarki constructor wants char* argument. Why? It's a very dangerous class. For example, your program is evidently wrong: Melarki destructor called for wholeMelarki will try to deallocate "Stuff" literal in static memory!

Alas, for backward compatibility such (wrong) literal usage treated as deprecated (but not invalid).

You can fix this error if you redesign this class - deallocation bomb from the scratch...

freelancelote commented: Thank you +1
ArkM 1,090 Postaholic

If unlucky user accidentally types a wrong char your program comes to loop forever because subsequent cin inputs do nothing until cin.clear() call.
Always check input result, for example:

if (cin >> number) {
   // that's ok
} else {
   // eof or not-a-number
   // Recovery? It's the other story...
}
ArkM 1,090 Postaholic

It's a UNICODE string. Use WideCharToMiultiByte to convert share name to ordinar string.
May be better try NetShareGetInfo?
Apropos, "No special group membership is required for level 0 or level 1 calls" only...

ArkM 1,090 Postaholic

No need to pass references to arrays. In actual fact a pointer to a 1st element of an array passed. Array contents never copied when passed as argument.

What for all these ordinar functions are collected in a class?

ArkM 1,090 Postaholic

1. Let's suppose that you have a collision with word "table". The LinearProbing finds a new free location then places the word into this cell. But the next occurence of the word "table" gets collision again - and linearProbing finds the next free location, it does not check if the word "table" was placed in the hash table! That's why you have next occurences of the same word in resulting hash table. Don't forget to wrap around search index in a new (correct) linearProbing loop...
2. DataIn >> getString gets not a word as a sequence of letters but all chars until whitespace occured. That's why you have such items as "539," or "word" and "word.". Add a simple item preprocessing (use isalpha() from <cctype>, for example) to select true words only.
3. Use c_str() string class member functions, not data(), The last one does not garantee that it's C-string with zero byte terminator.
4. Add hash table overfow check NOW! Never ever say that "My current list is less than
130 elements so no need to worry about space at this time" !!!
5. It seems you are writing a program in C++. Where is a class (at least a struct) HashTable? Why you have wrote obviously C-style code in C++? Why linearProbe does not know about hash table capacity?..

I think you are capable to correct all these defects yourself.
Good luck!

ArkM 1,090 Postaholic

Where was defined the type ptr? Why Node and node typenames occured in err messages?
See also error C2244 description in MSDN...

ArkM 1,090 Postaholic

You are trying to build absolutely senseless, absurd class NoFather (remember The House That Jack Built... ;) ?):

class NoFather {
...
private: NoFather DataNoFather;
};

Well, we have an object of type NoFather which has a member of type NoFather which has a member of type NoFather...

Formally at the point of DataNoFather declaration all the class NoFather was not completely constructed (that's why you get the message). In actual fact you are trying to construct an impossible thing...

freelancelote commented: Thanks. +1
ArkM 1,090 Postaholic

What is a clock tick equal to in ctime??

The time_t type is an implementation-defined arithmetic type capable of representing times. Use difftime function to get the difference between two times of type time_t in seconds as a double value:

#include <time.h>
...
    time_t t;
    time(&t);
    printf("time_t step %f sec\n",difftime(t+1,t)); // time_t precision

As usually, it's equal to 1 sec (but it's not the language standard requirement).

ArkM 1,090 Postaholic

Both C and C++ provide for (implementation defined) asm declaration (builtin assembler code) so the formal answer is "Yes, you might do that". Can you - that's a question.

It is better to bootstrap a new system from the scratch in C because the C runtime support is much more simpler than for C++ one (for example, imagine proper stack unwind after C++ exception code). That's why sometimes C called a very high level assembler...

ArkM 1,090 Postaholic

I don't see any MiniDump class in your post (only MiniDumpHelper), but...

Obviously SetUnhandledExceptionFilter wait a pointer to ordinar function (exception handler). But non-static member function is not an ordinar function and a pointer to it is not a pointer to ordinar function. Make it a static mamber (if possible): static member functions treated as ordinar.

Can't say more on this scant info...

ArkM 1,090 Postaholic

1. Where is an object stored? All non-static members stored there, in the same place:

MyClass ImInStaticStorage;

void where() {
    MyClass ImOnTheStack;
    MyClsss* pointToTheHeap = new MyClass;
    ...
    delete pointToTheHeap;
}

2. Initially it points to nowhere if you don't initialize it (has unpredictable value).
3. What to do with a pointer member in the class destructor: it depends... If the class object "owns" the referred object (for example, you allocate referred object in a class constructor), you must delete it (no need to assign 0 after that). If you saved this pointer value into the member but don't control life time of the referred object - do nothing.
About int member: int is a simple basic type, no destructors for basic types. Don't worry about int members destiny after destruction...

Privatness is a member name accessibility (not storage class) attribute.

freelancelote commented: Exactly what I needed +1