Radical Edward 301 Posting Pro

Your code has too many problems for Ed to cover in detail right now, so here is a simple function that works using the library functions strcspn, strspn, and printf for any heavy lifting. If you cannot use strcspn or strspn, the problem can be broken down into the tasks they perform:

#include <stdio.h>
#include <string.h>

void split(char const *s)
{
    while (*s)
    {
        size_t last = strcspn(s, "-");     // Find the end of the token
        printf("Found '%.*s'\n", last, s);
        s += last;                         // Skip the token
        s += strspn(s, "-");               // Skip adjacent delimiters
    }
}

int main()
{
    split("HEllo-le-t-me-confirm-it");
}
Radical Edward 301 Posting Pro

system() returns an integer, but popen()'s first argument expects a string. What should be done depends on what you want to happen, but Ed would guess this:

ptr = popen(command, "r");
Radical Edward 301 Posting Pro

> Not all of them, just those inside the KeyValue class.
Are you sure all of the methods are implemented and everything is being exported to the DLL?

Radical Edward 301 Posting Pro

Do all functions from stdlib.lib give you a linker error?

On a side note, Ed does not get warm and fuzzies from the name "stdlib.lib" because there is already a compiler-supported stdlib.h, which might have a corresponding stdlib.lib.

Radical Edward 301 Posting Pro

Take sign out of the equation, maybe?

int r = rand() % 190 - 95;
Radical Edward 301 Posting Pro

The two programs are running as separate processes, so you need to use IPC.

Radical Edward 301 Posting Pro

The ignore() method will flush cin, but it is better not to need to flush by always reading whole lines. :) Boost's lexical_cast<> makes it easy.

string teacherName;
int teacherID;
string line;

cout << "Enter ID: ";
getline(cin, line);
teacherID = lexical_cast<int>(line);
cout << "Enter Name: ";
getline(cin, teacherName);

If you do not want to install Boost, lexical_cast<> can be written with string streams.

#include <sstream>
#include <typeinfo>

namespace Ed {
template <typename Target, typename Source>
    Target lexical_cast(Source arg)
    {
        std::stringstream interpreter;
        Target result;

        if (!(interpreter << arg && interpreter >> result))
            throw std::bad_cast("Ed::lexical_cast<>");

        return result;
    }
}
Radical Edward 301 Posting Pro

> A google search reveals that it is normally used to access "hidden" members etc.
Not really. The common use is linking names to a namespace either in definition or use:

class Foo {
public:
    void method();
};

// Scope resolution in name definition
void Foo::method()
{
    // ...
}
#include <iostream>

int main()
{
    // Scope resolution in name use
    std::cout << "hello world" << std::endl;
}
Radical Edward 301 Posting Pro

What operating system are you using?

Radical Edward 301 Posting Pro

C++ uses the :: operator for scope resolution.

using namespace System::Windows::Forms;
Radical Edward 301 Posting Pro

Too many parentheses, says Ed. ;) Look at the expansion of the macro and you will see something like the following.

(for (<init>; <condition>; <increment>))
{
    <body>
}

Control flow statements are not expressions that can be wrapped in parentheses.

Radical Edward 301 Posting Pro

The OpenFileDialog class does all of the work of that.

Radical Edward 301 Posting Pro

> can you help me actually understand how this regex function work
Ed used ".*" to capture any number of characters instead of "[A-Za-z0-9]" to capture one instance of an alphabet letter or digit. There is also a named group, the "?<TITLE>" part, to make it easier to find the matched substring. You can use an unnamed group and access the Groups collection by index, but it is less convenient to find the one you want because there are other matched groups aside from the one in parentheses.

Match m = Regex.Match(source, "book_title='(.*)'");

// See all available groups
foreach (var group in m.Groups)
    Console.WriteLine(group);

// Get the substring group
Console.WriteLine(m.Groups[1]);

This is a handy reference.

Radical Edward 301 Posting Pro

Who knows what the title might contain, so capturing everything is a good idea. And a named group makes it easier to access the match.

using System;
using System.Text.RegularExpressions;

namespace Ed {
    public class Program {
        static void Main(string[] args) {
            string source =
                "contents=false\n" +
                "book_title='The Old Man and His Sons'\n" +
                "sections=[\n" +
                "'The Old Man and His Sons'\n" +
                "]";

            Console.WriteLine(Regex.Match(source, "book_title='(?<TITLE>.*)'").Groups["TITLE"]);
        }
    }
}
Radical Edward 301 Posting Pro

Properties and events are the recommended way of making forms talk to each other. How to do that depends on how the main form loads other forms, but in Edward's experience, passing shared data through the form constructor is usually good enough.

Radical Edward 301 Posting Pro

If either method is faster, it will be memset(). memset() is a compiler provided function, and it might use tricks to run as fast as possible on the target platform.

Radical Edward 301 Posting Pro

No. Decompilers exist, but they are generally very poor due to the lossy process of compilation.

Radical Edward 301 Posting Pro

C++ does not have properties like C#. You can use methods though.

class Example {
public:
    int parameter() const { return param; }
    void parameter(int value) { param = value; }
private:
    int param;
};
Example text;
text.parameter(value);
cout << text.parameter() << '\n';
Radical Edward 301 Posting Pro

> who is this OP and Ed???
OP is you, and Ed is Edward. :)

Radical Edward 301 Posting Pro
std::cout << "\\";
Radical Edward 301 Posting Pro

> They don't want to define the function more than once. Your example defines it once for each derived class.
If you were confused by it, then Edward's example failed completely. Apologies. It was meant *only* to show how to use polymorphism, not an attempt at a realistic solution to the OP's specific requirements. In the real GetInput(), Ed would expect a shared algorithm to use the virtual interface for customizing parsing.

void GetInput(Base& obj)
{
    std::string token;

    obj.open();

    while (obj.incomplete() && std::cin >> token)
        obj.add(token);

    if (obj.incomplete())
        throw std::runtime_error("Incomplete on close");

    obj.close();
}

Without details on what the objects do and what GetInput() is supposed to do, a realistic example is impossible. So Ed did not even try.

Radical Edward 301 Posting Pro

> Well the OP wants default arguments, which he can't get in C
It is not always practical to switch programming languages, even when the languages are highly compatible like C and C++. The OP is using C for a reason, and we should not dismiss his choice so readily. ;)

> you know of any work-abouts?
Yes. Ed posted a link with ideas on how to get default arguments in C.

Radical Edward 301 Posting Pro

> when i press ctrl+a it dosen't select the text
Some other keyboard events may be conflicting. Edward has not issues in a sample form.

> what is ""txtWhatever_KeyUp"" is it a text name that u declared or is it with in the system
Both. :) Visual Studio generates event handler names by using the name of the control and the name of the event separated by an underscore: <controlName>_<eventName>. You can call it whatever you want though, it is just another method.

Radical Edward 301 Posting Pro

> This thread can(should) be moved right?
Why? It is not confirmed that the OP even *wants* C++, and errors in compiling your sample code strongly suggests that he is trying to compile as C. Ed is not convinced that "use C++" is the right answer to the question here.

Radical Edward 301 Posting Pro

Polymorphism to the rescue!

#include <iostream>

class Base {
public:
    // Edward believes in abstract base classes
    virtual void method() = 0;
};

class Child1: public Base {
public:
    virtual void method() { std::cout << "Child1!\n"; }
};

class Child2: public Base {
    virtual void method() { std::cout << "Child2!\n"; }
};

void function(Base& obj)
{
    // Use the virtual interface to engage polymorphism
    obj.method();
}

int main()
{
    Child1 c1;
    Child2 c2;

    function(c1);
    function(c2);
}
Radical Edward 301 Posting Pro

> I have yet to experience deadlock.
Apologies for the confusion. Ed wrote "deadlock" while thinking "race condition". Too much coffee, or not enough? ;)

> Why is it more exception safe to read and pop separately? I can't think what the exceptions would be?
Here is readRemove() with the next logical step of generalizing the contained type.

template <typename T>
T multiQ<T>::readRemove()
{
    boost::unique_lock<boost::mutex> lock(m_mutex);

    if (!m_queue.size())
        m_cond.wait(lock);

    // 1) T's copy constructor might throw
    T returnVal = m_queue.front();

    // 2) Never throws
    m_queue.pop_front();

    // 3) T's copy constructor might throw
    return returnVal;
}

The problem is the line marked 3. If the copy constructor throws an exception, the stack unwinds without passing returnVal back to the caller. But the queue's state has already changed, so the value is lost.

> I would be interested to know where you would put try and catch blocks in this code (or some part of it).
There is no need for try/catch unless the function can safely recover. Pushing a value that was popped is not guaranteed to be a nothrow operation, so it is unsafe. The right way to go about fixing the problem is to avoid it in the first place instead of trying to clean up the mess after it happens.

void multiQ<T>::readRemove(T& returnVal)
{
    boost::unique_lock<boost::mutex> lock(m_mutex);

    if (!m_queue.size())
        m_cond.wait(lock);

    // 1) T's copy constructor might throw
    returnVal = m_queue.front();

    // 2) Never throws
    m_queue.pop_front();
}

Everything after copying the value is …

Radical Edward 301 Posting Pro

Edward answered your question in the 'C' forum...

Radical Edward 301 Posting Pro

nbaztec, this is the C forum. C++ does not work here. ;)

> I want a function which can return a string and also it should be able to take DEFAULT string arguments....
C does not support either default arguments or function overloading, so the simple answer is you cannot do it. The not so simple answer is you can probably do it with compiler extensions and/or tricks, but the end result is probably not worth the extra effort and complexity. You can read more on Stack Overflow.

Radical Edward 301 Posting Pro

If malloc() is setting errno to ENOMEM, try calling getrlimit() to get the specified limit of the RLIMIT_DATA resource.

#include <sys/resource.h>
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    struct rlimit rlim;

    if (getrlimit(RLIMIT_DATA, &rlim) == -1) {
        fputs("getrlimit() failed\n", stderr);
        return EXIT_FAILURE;
    }

    printf("Soft Limit: %lu\n", (unsigned long)rlim.rlim_cur);
    printf("Hard Limit: %lu\n", (unsigned long)rlim.rlim_max);

    return EXIT_SUCCESS;
}

If the limit is too low and you have permission to increase it, setrlimit() will do that for you.

Radical Edward 301 Posting Pro

Edward prefers SQL Server with the DbProvider factories.