ArkM 1,090 Postaholic

1. About C4716: didn't you know that double F_Ite() function must return double type value? And where is return anything-of-double_type in the function body? It's your code, you have wrote double F_Ite() ...
2. Use code tag with the language specifier (see this forum announcements):
[code=cplusplus] source

[/code]
It's impossible to cope with this unformatted nightmare!
3. There are two common ways to "return" several values:
3.1 Declare several function parameters (pointers or references to targets).
3.2 Declare a proper struct or class compound type then fill the object of this type and return it as a function value.

tux4life commented: The actual thread solver :) +9
ArkM 1,090 Postaholic

The wittingly wrong statement in OP code is delete buffer; - must be delete[]buffer; . Yet another defect: insufficient error check-up.

long GetFileSize(ifstream &file)
{
    static const streamoff badPos(-1);
    if (!file)  // test added
        return -1;
    streamoff temp = file.tellg();
    if (temp != badPos && file.seekg(0L, ios::end)) {
        streamoff end = file.tellg();
        if (end != badPos && file.seekg(temp, ios::beg))
            return static_cast<long>(end);
    }
    return -2;
}

/// Load the file to fileS string, return filesize. 
/// Non-positive returned if failed
long FileToString(const string &file_path, string &fileS)
{
	ifstream input(file_path.c_str(), ios::binary);
    if (!input) { // simple and clear stream state test
        fileS.clear(); // no contents
        return -1;
    }
	long size = GetFileSize(input);
    if (size <= 0) { // filesize test added.
        fileS.clear();
        return -2;
    }
	char* buffer = new char[size];
    if (input.read(buffer, size)) {
        fileS.reserve(size+size/10); // add reserve
	    fileS.assign(buffer, size);
    } else {
        size = -3;
    }
	delete [] buffer; // [] inserted!
	//input.close(); // no need: let destructor works
	return size;
}

About wrong filelist parsing (adatapost's tip):

If you want a portable code, never use FileToString to load line-oriented filelist file. It's the case where binary (low-level) stream/string processing is an absolutely irrelevan method. The old good std::getline is the best and the portable tool to "tokenize" a simple text file!

By the way, never add non-inline function definitions in .h files! Have you ever heard about separate compilation? Only function prototypes are placed in .h files.

CppFTW commented: Thanks! +1
ArkM 1,090 Postaholic

Are you sure that your method is not efficient?
Why?..
What's your efficiency criterion?

Salem commented: Getting someone else to do it with the minimal amount of explanation ;) +34
ArkM 1,090 Postaholic

Of course, all possible in C++ ;)
That's an improvisation:

/// suite.h (class Suite definition)
class Suite
{
public:
    Suite() {}
    Suite(const Suite& suit):value(suit.value) {}
    static const Suite 
        Hearts,
        Clubs,
        Diamonds,
        Spades;
    /// that's all, add some methods...
    const string& str() const { return value; }
    /// add some syntax sugar:
    operator bool() const { return !value.empty(); }
    bool operator ==(const Suite& suit) {
        return value == suit.str();
    }
    bool operator !=(const Suite& suit) {
        return value != suit.str();
    }
protected:  // there are four colours only
    Suite(const char* suit):value(suit) {}
private:
    string value;
};
inline // add stream output support
ostream& operator <<(ostream& os, const Suite& suit) {
    return os << suit.str();
}
/// suite.cpp (class Suite implementation)
const Suite 
    Suite::Hearts("Hearts"),
    Suite::Clubs ("Clubs"),
    Suite::Diamonds("Diamonds"),
    Suite::Spades("Spades")
    ;
/// test.cpp:
/// more syntax sugar for lazies
const Suite& 
    Hearts = Suite::Hearts,
    Clubs  = Suite::Clubs,
    Diamonds = Suite::Diamonds,
    Spades = Suite::Spades
    ;

int main()
{
    Suite suit;
    suit = Spades;
    Suite card(Clubs);
    if (card && suit == Spades)
        cout << suit << '\t' << card << endl;
    return 0;
}
tux4life commented: ArkM, always making the threads fun to read :P +9
ArkM 1,090 Postaholic

>I want the minimal pointer because it is the left most node for my tree.
The leftmost node in the tree is not the same as the minimal pointer!
Moreover, a pointer value does not bear a relation to the node position in the tree.
Make a loop from the root via child[0] pointers until you have found a leaf - that's a node with an empty child vector. That's the leftmost node of the tree (probably ;))...

ArkM 1,090 Postaholic

>i checked for Nov and for Dec
Hmm... For December the code returns a wrong answer months(0)...
Well, the right answer is:

currentMonth % 12 + 1

;)

yun commented: U r Best Man.. +1
ArkM 1,090 Postaholic

A day ago csurfer's algorithm solved the problem. That's "pipelined" version:

int i, j = rand()%20;
    for (i = 0; i < 20; i++)
        array[i] = (i != j)*(rand()%9 + 1);

In addition: it's impossible to add another level of randomness by random shuffles or other tricks while we are using the same (extremely bad ;)) rand() generator.

ArkM 1,090 Postaholic

Try to append LL suffix to long long constants.

Salem commented: ArkM blazes in with both barreLLs for the win ;) +33
tux4life commented: Sometimes it's so simple that you even don't think about it :P +8
ArkM 1,090 Postaholic

All except '\r' and (may be) quotes ;)

Do you really want to study C i/o basics on DaniWeb forum?
Better search for a good C i/o tutorial. There are lots of good links...

csurfer commented: :D Great honesty buddy !!! "May Be" ;) +2
jephthah commented: nothing personal, but that is not correct. -2
Ancient Dragon commented: yes it is correct. +36
ArkM 1,090 Postaholic
for (int i = 0; i < 20; i++)
ArkM 1,090 Postaholic

What's an excited title for help request: I don't know!!...
Next time try to invent more sensible phrase...

It's a well-known ;) fact that

lcm(a,b) = (a/gcd(a,b))*b

where gcd means greatest common divisor.
Euclidian algorithm for computing gcd - see:
http://en.wikipedia.org/wiki/Euclidean_algorithm
It's so easy...

Don't use global variables in this simple (and others) program. For example, declare IsItDiv function with two parameters - n and i. However no need in this function in the recommended solution.

ArkM 1,090 Postaholic

Step by step instruction:
1. Start Visual Studio
2. Select Help | Index
3. Type LNK2001 in Look For field
4. Click on LNK2001 list element
5. Read about LNK2001 error
6. Error correction: obvious after steps 1-5
About LNK1120:
7. Close Visual Studio
8. Do the same procedure as above but type LNK1120

tux4life commented: Haha! +7
ArkM 1,090 Postaholic

>I am talking about the programming interface ArkM, it is drag and drop just like VB
>I'm out of this thread, tired of being treated like a dumbass.
I hope now you will have a time to read Qt documentation: Qt Creator (probably it's that damned drag and drop interface) is an optional tool in Qt SDK. You (and me) can create Qt GUI applications without any visual add-ons...

killdude69 commented: Thank you ArkM, for not doing like Siddhant and slandering my oppinion just because you didn't like it. Although your comment may have been passive aggressive, you did it in a way that wasn't too disrespectful. For that, I give you respect. +1
ArkM 1,090 Postaholic

>c is generally slow compared to other programming language.
>Just out of curiosity, what languages should be faster?
Assembler, fortran?
Look at these wonderful benchmarks: http://shootout.alioth.debian.org/
Slow C... ;););) Hot Ice...

jephthah commented: cool link. C kicks ass! +10
ArkM 1,090 Postaholic

How would I test if it IS empty.
Because I am currently using: if (fileName == "")

And I am using this for over 6 if statments.

Didn't you familiar with logical not operator?

if (!*fileName)
// or
if (fileName[0] == '\0')
// or
if (strlen(fileName) == 0)

By the way, fileName == "" is equal to false in all cases. Why? Think about pointers comparison ;)

ArkM 1,090 Postaholic

It's legal to compare any pointer value with null pointer or any others pointer values of the same type.
Better post your code fragment with segmentation fault. It's annoying to download the whole source, didn't you understand it?

tux4life commented: Good clarification! +7
ArkM 1,090 Postaholic

I have found this exotic Number_1_C... panopticon at Ohio state university site. It looks like an attempt to convert the C++ language to an incomprehensible slang for dedicated persons. As far as I could judge it's not so easy to understand lots of special conventions, mysterious macros and other tricks embeedded in this stuff...

How sad! :(

Salem commented: Yes, this is unadulterated brain-rot which will cripple the students for life. +32
ArkM 1,090 Postaholic

You can deallocate dynamically allocated memory here, there and everywhere:

int main()
{
  al = new Vertex*[numLocations];
  ...
  delete [] al; // al is visible
  ...
  // or
  f(al); // al as argument
  ...
}
...
void f(Vertex* p)
{
  delete [] p; // array of Vertex is deallocated
  ...
}

Name scope (name visibility) and storage duration (span of life) are different notions. In actual fact to deallocate memory obtained from operator new you need not al variable per se but the pointer value which refers to the memory chunk.

Daria Shmaria commented: helpful, clear, concise +1
ArkM 1,090 Postaholic

Yes, old good (or most likely bad) VC++ 6.0 can't compile String member template from std_lib_facilities.h. However why #include "iostream" instead of <iostream>?

Better try to download and install VC++ 2008 Express (or Code::Blocks with MinGW/gcc compiler)...

colmcy1 commented: Thanks for good advice +1
ArkM 1,090 Postaholic

I was trying to understand what's the ASCII value of a string of text (about 10 seconds or even more)... Alas... Can you explain what is it?

Now I see why you cannot seem to figure out how to convert the text into an ASCII value.

However if you want to get int value of a single char, that's it:

char c = '!';
int  i = c;
// or (int)c
tux4life commented: LOL, The ASCII value of a string :D +7
amrith92 commented: Maybe he meant: ASCII - A whole S(tring) C(onversion) to I(ntegral) I(ntegers)... :) +1
ArkM 1,090 Postaholic

iamthwee.thank(you).for(post(number(2)));
;)

iamthwee commented: For getting the number of open and closing parenthesis correct! +21
ArkM 1,090 Postaholic

tux4life, don't torment the unhappy C++ programmer, tell him/her about while(f>>i) construct ;)

tux4life commented: Srry, forgot to tell it :D +7
ArkM 1,090 Postaholic

>Or do you know the 'ultimate' way?
Why not?

char* condense(char* s)
{
    if (s) {
        char* p = s;
        char* q = s;
        /* (never write so:) */
        do if (*p != ' ')
           *q++ = *p;
        while (*p++);
    }
    return s;
}

;)

jephthah commented: that's a good way +9
ArkM 1,090 Postaholic

cout << r[0] << r[1] or cout << r.substr(0,2) ;)

siddhant3s commented: The first one was funny. +7
ArkM 1,090 Postaholic

Remember KISS principle: no need in temporary strings! ;)

tux4life commented: Keep It Simple Stupid!! You're right! +7
ArkM 1,090 Postaholic

Please, post your code with code tag:
[code=cplusplus] source

[/code]
Read this forum announcement: http://www.daniweb.com/forums/announcement8-3.html

tux4life commented: Yes. +6
amrith92 commented: Absolutely a must for code that long... +1
ArkM 1,090 Postaholic
ArkM 1,090 Postaholic

yes it is.. performance matters as tokenizing is the crucial part of the application

Impossible!

Can you prove it? How many bytes per second is OK? What's i/o channels capacity?

Even if it's true: serious applications are never discussed on the forums like DaniWeb. True crucial parts of such applications are never assigned to programmers who can't tokenize a line with two-char delimiters ;)..

tux4life commented: ROFLMAO!! Perfect, just perfect! +6
ArkM 1,090 Postaholic

Try winbgim or winBGI libraries - BGI for Windows (search Google).
Regrettably (or fortunately), I have never used these libraries...

NicAx64 commented: using the legacy API's , good recycle of legacy expertise. +1
ArkM 1,090 Postaholic
/** Undestructive tokenizer. 
    @todo Add tsz < toksz test 
 */
const char* getTok(const char* s, char* tok, int toksz, const char* delim)
{
    if (s && *s) {
        int dlen = strlen(delim);
        const char* p = strstr(s,delim);
        int tsz = (p? p - s: strlen(s));
        if (tsz)
            memcpy(tok,s,tsz);
        tok[tsz] = '\0';
        return s + (p? tsz + dlen: tsz);
    }
    return 0;
}

int main()
{
    char tok[80];
    char str[] = "123#!45!2#!678#!666#!45!6#!";
    const char* p = str;
    while ((p = getTok(p,tok,sizeof tok,"#!")) != 0)
        printf("%s\n",tok);
    return 0;
}
jephthah commented: solid +9
ArkM 1,090 Postaholic

Place this function into the separate .cpp file:

void ShowText(const char* filename)
{
    ::ShellExecuteA(::GetDesktopWindow(),
        "open",
        "notepad.exe",
        filename,
        0,
        SW_SHOWNORMAL);
}

Include <windows.h> dependency into this file only.
This function works in console applications too.

tux4life commented: Good job! +5
ArkM 1,090 Postaholic

What's a nightmare! Have you ever seen a simplest book on programming languages syntax?..

>an expression is an assignment to a variable like...

What is an expression in C++:

An expression is a sequence of operators and operands that specifies a computation. An expression can result in a value and can cause side effects.

It's NOT an expression: int a = 1; . It's a declaration.

Now have a look at conditional expression in C++:

...
logical-or-expression:
  logical-and-expression
  logical-or-expression || logical-and-expression

conditional-expression:
  logical-or-expression
  logical-or-expression ? expression : assignment-expression

So condition and conditional expression are different things.

>An assignment is a statement...

An assignment is an expression in C++.

assignment-expression:
  conditional-expression
  logical-or-expression assignment-operator assignment-expression
  throw-expression

There is assignment (binary) operator in this language. There is an expression statement in C++, that's it:

expression ; // expression + semicolon

An example of assignment without any statement:

Class c(a = b); // It's a declaration
// a = b is not a statement here
// A statement has no value in C++ (C++ is not Algol 68)

An example of assignment in return statement:

return mSize = n; // not an assignment statement!

>I would describe an expression as something which has a value and can be passed to a function
Look at

f(a = b); // because assignment is an expression

and

void f();
// f() is an expression (operator(), operand f)

but you CAN't pass its value (of …

ArkM 1,090 Postaholic

how do i create a set method to get the fstream input file.

in need to be able to define the file location in the main method.

class a
{
private:
	ifstream fileOne;
	ofstream report1;
	
	
public:
	void setinput(std::ifstream& in);
	void setoutput(std::ofstream& out);
	
};

how can i code these set methods.

Use pointers:

class A // Better use capitalized names for your classes
{
public: // Better place public interface first
  A():inFile(0),report(0) {}
  void setinput(std::ifstream& in) { inFile = &in; }
  void setoutput(std::ofstream& out)
  {
    outFile = &out;
  }
  void report();
  ...
private: // it's not so interesting for the class user
  ifstream*  inFile;
  ofstream* outFile;
};
void A::report()
{
  if (outFile) {
    ofstream& f = *outFile;
    f << ...;
    ...
  } // else no output file settings...
}

Be careful: you must provide these fstream existence while A::report is working. So it's not a very robust architecture (no matter with or w/o pointers).

newcook88 commented: THank you for the Help:) +1
ArkM 1,090 Postaholic
tux4life commented: Earns some rep I think :P +4
ArkM 1,090 Postaholic

The answer: use anonymous namespace...

using std::cout;

class A // External linkage name
{
public:
    void f() { cout << "::A:f()\n"; }
};
namespace { // Internal linkage area:
    class A // Internal linkage name
    {
    public:
        void f() { cout << "LocalA::f()\n"; }
    };
    typedef A LocalA; // for local references
    void F() 
    {
        cout << "F()...\n"; 
        A a; a.f(); ::A aa; aa.f(); 
    }
}
// need type alias if ::A is visible here.
void FF() { cout << "FF()...\n"; LocalA a; a.f(); }

int main()
{
    F();
    FF();
	return 0;
}

Try this method for separate modules.
Moreover: anonymous namespace is a preferred way to force internal linkage in C++ (instead of C-style static keyword).

tux4life commented: Finally someone which just answers his question :) +4
ArkM 1,090 Postaholic

>I looked on google ...
After ~15 seconds:
http://www.codeproject.com/KB/recipes/csha1.aspx
http://www.packetizer.com/security/sha1/
What's a problem?

Salem commented: But you've got a +50 staff of finding, and all they have is a -10 wand of rummaging ;) +31
ArkM 1,090 Postaholic
bool conjugated(const std::string& s1, const std::string& s2)
{
  return s1.size() == s2.size() &&
        (s1+ s1).find(s2) != std::string::npos;
}

;)

tux4life commented: You amaze me everytime, again and again, you write the best and most efficient code possible :) +4
iamthwee commented: I concur +19
ArkM 1,090 Postaholic

Other failed tests:

f("\""); // Strip me!
ch = '\"'; // Strip me!

Probably, this is too much!(?) :

#if 0
/* Code wrecks...
#endif
cout << "Hello, Sky Diploma!\n";
ArkM 1,090 Postaholic

Of course, operator ~. What's a shame :( Sorry.

tux4life commented: Never mind, that's because you're used to solve the most sophisticated problems :P +4
ArkM 1,090 Postaholic

> guess i forgot about this particular epic battle...
It's not the echo of the epic battle, it's a regular untidiness ;)
See the language standard, for example: ...null character term used...
In addition the C has a case-sensitive syntax ;)

jephthah commented: ok :) +9
ArkM 1,090 Postaholic

the fact that it doesnt terminate the string with a NULL is the error.

a string must have a NULL termination, or else it's just a character array.

Please, don't forget: NULL is a ponter value in C. You (and me) can't terminate the string with a pointer ;)

jephthah commented: ok, you got me :) +9
ArkM 1,090 Postaholic

Yes I wanted to use pointers so that I could understand how to use them. Pointers are very confusing to me.

You have used pointers in a[i] construct because a[i] <=> *((a)+(i)) by the language definition. You have used pointers in sort(int a[],... construct because an array argument converts to the pointer to the 1st element by the language definition. It's not the best code to become familiar with pointer concept and handling. Better try to implement any pointer-based data structure (list or tree, for example).
Otherwise you have a good chance to become OOP programmer (alas, OOP means Only One Project, not Object-Oriented Programming).
;)

tux4life commented: You're absolutely right :P +3
ArkM 1,090 Postaholic

Take into account that

123456 * 654321 * 80779853  == 6525384681074833728

but std::numeric_limits<long>::max() is equal to 2147483647 on 32-bit processors (integer overflow is not detected).
Try long long type (it's supported by modern compilers now), its max value is 9223372036854775807.
Otherwise try one of big int class libraries...

ArkM 1,090 Postaholic
/// fast int test (except possible overflow)
bool isInt(const std::string& s)
{
    static const size_t npos = std::string::npos;
    static const std::string digits("0123456789");
    size_t pos = s.find_first_not_of(" \t");
    bool res = pos != npos;
    if (res) {
        if (s[pos] == '+' || s[pos] == '-')
            pos++;
        res = (pos < s.size()
            && s.find_first_not_of(digits,pos) == npos);
    }
    return res;
}
tux4life commented: Lol, I forgot to handle the signs also :) Good job ArkM !! +3
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

That's a nightmare... Is it a program in C? No, of course (see reinterpret_cast). But if it's a program in C++, where is operators new instead absolutely inadequate mallocs?!

I can't understand why you allocate memory then overwrite the pointer obtained from malloc in the next statement (and you? )...
It seems the best advice: think again and redesign this code from the scratch (don't forget to select the implementation language)...

jephthah commented: whew. i'm glad someone else thought so, too :) +8
iamthwee commented: touche +19
ArkM 1,090 Postaholic

>AND it with a bitmask 0x00FF to get the lower 16 bits...
It's one-byte mask... Where are 16 bits?..
>If bit 15 == 1, then OR all ones into bits 16-31 using the bitmask 0xFF00...
It's one-byte mask too...
?

jephthah commented: glad you were paying attention :P +8
ArkM 1,090 Postaholic

Strange the following is working: final += hex_string; As far as I know hex_string is a pointer and final is a string, but I don't know whether the + operator is overloaded for data of type char* ...

Of course, it's impossible to overload operator + for char* type ;)
It's overloaded for std::string:

std::string std::string::operator+(const char*) const;

;)

tux4life commented: Now I'm sure :) +2
ArkM 1,090 Postaholic

Regrettably the OP question (and all the thread ;)) is a product of a misunderstanding of an array semantics in C++ (and C). If we have an array which is defined as int x[100] = {1,0,3}; then we have an array of 100 (one hundred) elements. The leading three elements have initial values {1, 0, 3} and other 97 elements have values 0 (zero).

Please, feel the difference between array element and array element value.

So the last phrase of OP was started from the false conclusion:

so only i have 3 elements...

Nope, you have 100 elements in this array and no need to count them in run-time. An array in C++ is a compound object of a fixed size defined at the moment of this object allocation.

Incidentally, PHP arrays have absolutely different semantics: they are chimeras of C++ STL std::vector and std::map (that's about count($...) in PHP)...

siddhant3s commented: Exactly +5
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