nezachem 616 Practically a Posting Shark

concatenate the capital letters that are followed by a space

I can think only of a 3-step solution (which looks ugly, but possibly it can be improved):
- replace all wanted spaces with, say, underscores:
s/ \([A-Z][^ ]\)/_\1/g'
- remove all remaining spaces:
s/ //g
- restore wanted spaces:
s/_/ /g'

Something like that...

nezachem 616 Practically a Posting Shark

In the ChanNameVAlign case you want to split at the transition from lowercase to uppercase:
s/\([a-z]\)\([A-Z]\)/\1 \2/g

In the OSDSettings, I don't see a non-contradictory criteria.

nezachem 616 Practically a Posting Shark

This is the linker command your gcc generated (I just broke it up into few lines for clarity:

c:/mingw/bin/../libexec/gcc/mingw32/4.6.2/collect2.exe -Bdynamic -u ___register_frame_info -u ___deregister_frame_info -o Pascal.exe c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../crt2.o c:/mingw/bin/../lib/gcc/mingw32/4.6.2/crtbegin.o -Lc:/mingw/bin/../lib/gcc/mingw32/4.6.2 -Lc:/mingw/bin/../lib/gcc -Lc:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/lib -Lc:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../.. -L/mingw/lib
-lgmpxx -lgmp
C:\DOCUME~1\DMS40\LOCALS~1\Temp\ccKxmt7C.o
-lstdc++ -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt c:/mingw/bin/../lib/gcc/mingw32/4.6.2/crtend.o

The linker works sequentially, and only puls stuff from libraries to satisfy references, which are currently unresolved. By the time the it sees -lgmpxx and -lgmp, there is nothing yet to link from them. You need to change the order, so that linker accounts your object first So, instead of

$ g++ -v -lgmpxx -lgmp -o Pascal.exe Pascal.cpp

do

$ g++ -v Pascal.cpp -lgmpxx -lgmp -o Pascal.exe 
nezachem 616 Practically a Posting Shark

First of all, you cannot manipulate names. A name is a property of a computer, and it should stay intact. What you need is to allocate a port over which the game communications would occur. This port number is to be known for all participating computers in advance.

In the discovery phase, the game shall broadcast the request (that is, send a UDP pachet to a said port at a broadcast address). If the server already exists, it shall reply with its IP address. If nobody replies in a sensible time period (and maybe even after a few retries), the game may assume there's no servers, and create one. Keep in mind that nothing happens instanteneously, so there's a possibility that two or more systems may simultaneously decide to become servers. Yuo need a protocol to detect and arbitrate such race.

Once the server is established, the rest is more or less trivial. I'd suggest to set the discovery stage aside for now. Make the server, and have it running at a known IP address. Let the clients connect to that address. Are there specific questions on how to do it?

nezachem 616 Practically a Posting Shark

I had to emphasize that ls (ell-es) is a command. Run it in the directory whe you run make, and post the output here.

nezachem 616 Practically a Posting Shark

In the valueAt, if the very first comparison fails you immediately enter the else clause and return 0. Get rid of else and move return 0.0 out of the loop.

nezachem 616 Practically a Posting Shark

Of course not. stosb increments EDI automatically.

thines01 commented: Good catch! +12
nezachem 616 Practically a Posting Shark

You never change the clipboard contents. You only copy the text into some global memory, which has no association with a clipboard. Look at SetClipboardData function.

nezachem 616 Practically a Posting Shark


Secondary issue: speed

In regards to speed, I need to write code that gets the job done as fast as possible. This was the simplest copy function I could think of, but I don't know whether it is the fastest. What is faster, fread/fwrite or getc/putc ? Or is there another standard function that can copy even faster?

The stdio buffers data by the same chunks, so the performance difference between fread and getc is in a number of function calls made. Of course fread would be called less times than getc, but I suppose the speed gain would be infinitesimal, comparing with the actual IO time.

I'm also not sure what the bottleneck is in regards to speed, as an portable drive takes more time to write to than for example internal memory. If I write a function that compresses files before they are copied, would that increase speed? Or would it just slow the read/write process down?

The real bottleneck is in transferring data to and from the peripheral device. You sure want to minimize the amount of data transferred, so yes, compression is a standard way to increase the performance.

nezachem 616 Practically a Posting Shark

Something tells me you are on a Windows system. There is a distinction between a text mode and a binary mode. In the first case the ^Z character does serve as an end-of-file marker. Open your files in a binary mode: pass "rb" as a second argument to fopen. Same goes for writing.

nezachem 616 Practically a Posting Shark

Add the line

cout << "fact = " << fact << endl;

right after line 24, and see what happens.

nezachem 616 Practically a Posting Shark

Does anyone have any ideas?

Of course. Assigning a pointer does not copy the string contents:

g_ppRecords[g_numRecords]->firstName =(char*) malloc(sizeof(token));
	g_ppRecords[g_numRecords]->firstName = token;

Now firstName points to token, not the memory you've allocated. That is, firstName in every record points somewhere into the input array, and most likely to the exact same place.

nezachem 616 Practically a Posting Shark

A mandatory reading.

vedro-compota commented: ++++++++ +3
nezachem 616 Practically a Posting Shark

so - there's no way to stop comparison thread safely using signals ?

No. The pthread_create man page explicitly says that
The set of pending signals for the new thread is empty

nezachem 616 Practically a Posting Shark

I don't think it is possible. What exactly are you trying to achieve? I mean, is using signals a requirement?

vedro-compota commented: +++++++++++ +3
nezachem 616 Practically a Posting Shark

The problem is that a Weierstrass product converges very poorly (my gut feeling is that it is worse than linear; correct me if I am wrong). That is, even 1e8 iterations may not be enough.

nezachem 616 Practically a Posting Shark

Well something must be different. My first recommendation is to attach a debugger, and figure out what exactly is failing. My second recommendation is to get rid of system(), and use rename() and unlink(); if you insist on system(), at least spell out explicit paths to mv and rm.

nezachem 616 Practically a Posting Shark

Define a generic node type; somewhat akin to

typedef struct node_s {
    enum node_type_t node_type;
    void * node_specific_data;
    node_s ** children;
} node_t;

You may need other fields as well.

Define "node constructors" for each language entity (terminals and nonterminals alike).

In the semantic action for each rule, call a relevant constructor, assign it to $$ , allocate the children array, and fill it up with pointers to child nodes, available as $1, $2 etc.

That's pretty much it. As soon as you have a grammar, this process is almost mechanical.

PS: tutorial

Stefano Mtangoo commented: Great step for me! +13
nezachem 616 Practically a Posting Shark

So, you passed FunctionToPass to ThreadProc as a parameter, which is correct. Now you need to actually call it:

DWORD WINAPI ThreadProc(LPVOID lpParameter)
{
    void (* function)() = (void (*)())lpParameter;
    function();
    return 0;
}
triumphost commented: Thanks a lot! +5
nezachem 616 Practically a Posting Shark

a bunch of preceding syntax errors

They are probably much more relevant. Start with the first one.

PS: I bet you are missing a semicolon somewhere in one of your .h files.

nezachem 616 Practically a Posting Shark

The presence of flags, and special casing of certain conditions usually indicate that something is wrong. For example, on a very first insertion you compare temp with arr[0], which has a garbage value. If that comparison fail, the next comparison accesses arr[count], and count is -1. Welcome undefined behaviour.

Looking closely, you'd realize that all the work is really done in lines 32-42, with small modifications (count shall be initialized to 0 BTW):

for(pos = 0; (pos < count) && (temp > arr[pos]); pos++)
        ;
    for(i = count; i > pos; i--)
        arr[i] = arr[i - 1];
    arr[pos] = temp;
    count++;

Make sure you understand why count must be initialized to 0, and how your special cases are automatically handled here.

Smartflight commented: Great code! +1
nezachem 616 Practically a Posting Shark

man strftime. The format string you need is "%Y-%m-%d %H:%M:%S".

nezachem 616 Practically a Posting Shark

Index, in fact. It's a long-standing math tradition.
From math it was assumed by Fortran (which is Formula Translator), where anything starting with I, J, K, L, M and N was implicitly integer. Then it became a programming tradition.

nezachem 616 Practically a Posting Shark

The problem has nothing to do with 64 bit types. Values you read are not garbage, but a very valuable port definitions:

struct ofp_phy_port ports[0];  /* Port definitions. The number of ports is inferred from the length field in the header. */

Which means, once you've

recv(connected, &features_rep, sizeof(features_rep), 0)

you need to inspect features_rep.header.length , figure out how many struct ofp_phy_port follow, allocate memory for them and read those data.

nezachem 616 Practically a Posting Shark

You have to understand how fscanf works. Where does it store the result of conversion, and what does it return.
In your case, all the numbers you read end up in input , while input1[] collects return codes (which all happen to be 1, indicating successful conversion of one field).

yurigagarin commented: very good information +1
nezachem 616 Practically a Posting Shark

The problem is not so much equal condition (which is infinitesimal), but the fact that you recalculate random(). In the failing case,

##            if random()*probA > random()*probB:
##                scoreA = scoreA + 1
##            elif random()*probA < random()*probB:
##                scoreB = scoreB + 1

the fact that team A loses (line 2 skipped) doesn't necessarily result in incrementing teamB's score.

That said, even the "working" case doesn't seem to be correct. You need to calculate random() once, normalize it to (0, 1) and compare to probA.

Gribouillis commented: indeed +13
nezachem 616 Practically a Posting Shark

Settings, line 7. Looks like a typo in the username.

nezachem 616 Practically a Posting Shark

a) Yes
b) C++ does not address this
d) Sort of (due to e)
e) Very much
f) Start here, then try to apply those ideas to your architecture (if it is not x86).

nezachem 616 Practically a Posting Shark

You forgot to chdir(strPathname.c_str()) The logfile is created, but in the wrong place.

iamthesgt commented: Thanks for the help. +3
nezachem 616 Practically a Posting Shark

This is a quite unusual way to serve connections. You don't need to shutdown a listening socket; the same one will accept new connections as many times as you want:

listen(serverSocket, 1);
    while(1) {
        clientSocket = accept(serverSocket, 0, 0);
        do_stuff(clientSocket);
        shutdown(clientSocket, SD_BOTH);
        closeSocket(clientSocket);
    }

In your code, after the line 51 you lose the handle to the listening socket forever. It is not affected by shutdown/closesocket anymore. The socket object is still sitting there interfering with a next one you are trying to create.

ktsangop commented: Useful answer +2
nezachem 616 Practically a Posting Shark

My guess is that a semaphore is just a system DWORD since all it does is count from 0 to some maximum value. See this link

I seriously doubt that.

nezachem 616 Practically a Posting Shark

I suppose that you need something like

si.hStdOutput = _PipeRead;
si.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
si.hStdError = GetStdHandle(STD_ERROR_HANDLE);
nezachem 616 Practically a Posting Shark

I am afraid you've misunderstood. The code is plain C. No porting effort required. Except maybe an olbanic case in the comment.

vedro-compota commented: +++++ +3
nezachem 616 Practically a Posting Shark

Hey guys. I'm working on a project where a parent process forks two children (so Process A is parent to both Process B and Process C). I need the children to write to the pipe so that the parent can see it. When I make a simple one child pipe to the parent, i got it working. But i'm hitting some snags here with two children. Currently, the parent reads nothing, as if the children never got to write to the pipe. I'm not amazing at pipes, so there very well could be a stupid mistake. Here's my code:

main()
{
    ...    
    pid[0]=fork();//Parent creates first child
    
    if (pid[0]!=0) { //If pid[0]=0, then process is child and should not fork
        pid[1]=fork(); //current process is parent, so fork a second child
    }    
        
    if (pipe(p)==-1) { //error
        perror("pipe call");
        exit(1);
    }
...
    exit(0);
}

How can I get these child processes to write properly so that the parent can read them? Thanks for the help!

The most serious error here is an order of events. This code first forks, then creates pipes. Each of the 3 processes create a unique, distinctly separate pipe, and they are not related to each other.

On the other hand, what happens in the correct sequence (first create a pipe, then fork, as in L5Sqr example):
fork clones the userspace, yet the pipe, which is a kernel object, is not cloned. That is, both processes refer to the same pipe, and may communicate through it.

nezachem 616 Practically a Posting Shark

At line 41, you always comparing t against s[1...], no matter how deep you are in the enclosing loop. If the string has a pattern at position 1, you'll match it many timers. Otherwise, you'll never match it.
In other words, initialization j=1 is wrong.

minimi commented: OMG, Thank you! +2
nezachem 616 Practically a Posting Shark

Notice that the blocks of code at lines 30-71 and 72-113 are nearly identical. The only difference is that "*" and "o" are swapped. Create a method doMove(String title, String self, String other) , and use it as

for(;;) {
        if(team) {
            doMove(name, "* ", "o ");
            team = false;
        } else if(team == false) {
            doMove(opo, "o ", "* ");
            team = true;
        }
    }

Not only your code becomes twice as short (which means twice less maintenance), you may immediately realize that the team variable is redundant. Really, the game loop becomes

for(;;) {
        doMove(name, "* ", "o ");
        doMove(opo, "o ", "* ");
    }

BTW, you need a way to detect an end of game situation and break the loop.

Now, let's get into the doMove itself. Notice that you test board[a][b] in each clause. Again, a redundancy must be eliminated:

if(board[a][b].equals(self) {
        ... Keep processing the move ...
    } else {
        System.prinln("invalid input");

}

And last but not least, you allow horrible violations of rules.

nezachem 616 Practically a Posting Shark

Short answer: system("cmd /c dir") Long answer: system() expects an executable. dir is not, it is a builtin.

nezachem 616 Practically a Posting Shark

1. Download and install a WDK.
2. Study the documentation and samples.
3. Find a datasheet for the device you want to drive.

After that a driver for a mouse-class device is a matter of one week.

nezachem 616 Practically a Posting Shark

Take a look at GNU plotutils.

nezachem 616 Practically a Posting Shark

Did you look here?

nezachem 616 Practically a Posting Shark

I don't know. I'm starting to think I may have imagined something

I think the confusion comes from the overcommit feature of some OSes. Indeed, memory allocation routine may just reserve the address space, and postpone actual mapping until the first access. So an object with the trivial constructor may remain in the aetherial state for a while. However, new would execute exactly when it is called.

mike_2000_17 commented: that makes more sense. thanks +14
nezachem 616 Practically a Posting Shark

One fairly obvious problem is at lines 14-15. The way it is written it means that a (phony) target classes depends on nothing, and the recipe is a very strange command. You want classes to depend on the list of class files with no recipe.
Join those two lines together.

nezachem 616 Practically a Posting Shark

At line 42 you call matrixCofact as if it returns the minor's determinant. I recommend to (a) make matrixCofact return double, (b) get rid of its third parameter (you don't use it anyway), and (c) change line 50 to return det . Of course, det should be just double (not a pointer).
PS: minor->elements at line 52 is wrong. It should be mat->elements[0].
PPS: You probably know that it is one of the least efficient algorithms.

nezachem 616 Practically a Posting Shark

>> you agreed with my original point that you're not supposed to store the password in the database?

I did???
Sorry if I has been unclear in my last post. I reiterate:
When providers keep passwords in the database, they do not violate the security protocol. In fact, they have no other way but keep them.

>> You weren't asking questions trying to learn about it

I was trying to prove that keeping hashes instead of passwords is inherently flawed. For me, the point of this whole exercise was to make you realize it. Sorry if I sounded offensive or unfriendly.

nezachem 616 Practically a Posting Shark

It is a standard logic based on a Newton-Raphson method. Here is how it works:
We are trying to solve an equation
x^2 - n = 0
Given an iteration X0, the next iteration X1 is an x-intercept of a tangential at X0. In a general form the tangential is
(y - Y0)/(x - X0) = f'(X0)
In our case Y0 is X0^2 - n and f' is 2*X0, that is
(y - X0^2 + n)/(x - X0) = 2*X0
For x-intercept, y is 0:
(-X0^2 + n)/(x - X0) = 2 * X0
or
n - X0^2 = 2*x*X0 - 2*X0^2
or
x = (X0 + n/X0)/2
which is your formula.

griswolf commented: Very clear +11
nezachem 616 Practically a Posting Shark

> What do you mean by that?

Consider the position:
W: Ke1, Rg1, Nf2
B: Kg8, Bg3
Is 1. Nd1 valid?. It passes the "geometrical validity" test, but makes possible 1. ... Bxe1 - the white King becomes exposed even though the Bishop is pinned. In your logic however, you would try to validate 1. ... Bxe1 all the way.

> How else can I do this though WITHOUT using IsValidMove or CanPieceBeTakenByEnemy?

As I said, IsSquareExposed() method is a way to go. Something along the lines of

IsValidMove(from, to)
{
    if(!IsPathOk(from, to))
        return False();
    PretendDoMove(from, to);
    if(IsSquareExposed(kingSquare))
        return False;
    return True;
}

IsSquareExposed(square)
{
    for_all_opponent_pieces(p) {
    if(IsPathOk(p, square))
        return True;
    return False;
}
David_Omid commented: This single piece of advice saved me a LOT of time! +2
nezachem 616 Practically a Posting Shark

checking if the king can be taken by an enemy piece

... shall not be tested for pins. You need a separate method to test for square exposure (instead of generic CanOtherPieceBeTakenAfterPieceMoving).

nezachem 616 Practically a Posting Shark

Your programs work fine (you may observe that by decreasing an usleep() timeout to a reasonable value). The problem is that a pipeline IO is fully buffered, and for n to obtain any input, m shall produce 4K of data.
Be patient... data will come... slowly...

nezachem 616 Practically a Posting Shark

They are the most efficient I could possibly make them. Any more efficient and i'd have to write it in assembly.

To begin with, both functions make library calls, which are totally uncalled for. A standard technique here is

while(*in_BinaryString)
        Result = (Result << 1) | (*in_BinaryString++ == '1')

The IntToBinary (which BTW fails for a negative argument) instead of calling memmove should just return Result + t; . Since Result is static, its last byte is initialized to 0 and shall never be touched:

char * IntToBinary(unsigned int in_Integer)
{
    static char Result[MaxLen];
    static char digits = { '0', '1' };
    char * dst;
    for(dst = Result + MaxLen - 1; in_Integer > 0; in_Integer >>= 1)
        *--dst = digits[in_Integer & 1];
    return dst;
}

I do prefer a digits array to a ternary for a reason of branch elimination. Assuming an ASCII code set, one may even do

*--dst = '0' + (in_Integer & 1);
TrustyTony commented: Looks neat +13
nezachem 616 Practically a Posting Shark

In Ubuntu, for example, you can do something like: sudo apt-get install g++

Don't forget sudo apt-get install build-essential