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

> for some reason the ReducedFraction function is not working

Perhaps, because you never call it.

nezachem 616 Practically a Posting Shark

What error are you getting? Replace line 24 with

printf("connect: %s\n", strerror(errno));

Don't forget to #include <errno.h>

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 call main somehow. Usually, it is

if __name__ == '__main__':
    main()
nezachem 616 Practically a Posting Shark
nezachem 616 Practically a Posting Shark

Think of the case of a list with 2 elements. Once you've deleted the last one, where does _first->_fore point to?
BTW, same applies to _last->_fore in a general case.

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

As usual, "doesn't seem to work" is not a helpful description of the problem. My wild guess is that you do not account for the newline character (which does appear in buff), and becomes an inherent part of certain words.

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

Depends on your development environment. Every IDE I know has one. If you calling gcc from the command line, then use gdb.

nezachem 616 Practically a Posting Shark

Run your program in a debugger. It will show you exactly where the segfault occurs, along with the function call sequence which lead to it. Usually it is more than enough to pinpoint the problem.

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

The way you wrote it, checkurl() is not a method of Ui_MainWindow class, but a standalone function. Give it a proper indentation.

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

If you compile that code the 2nd one is wrong.

Care to elaborate?

nezachem 616 Practically a Posting Shark

You're writing the entire array writePlanet each time you call save().

No. OP is writing a same nonsensical pointer multiple times. Here is the essential code:

void save(planet_t writePlanet[], int totalSize){
      for(count = 0; count<PLANET_SIZE; count++){ /**/
         fwrite( &writePlanet, sizeof(writePlanet), 1, outFile);
         printf("\n%s", writePlanet[count].name); /* Test to see if its writing. */
      }

writePlanet is a pointer. &writePlanet is a pointer to it (an address of some location in the save() 's stack frame). sizeof(writePlanet) is a size of a pointer.

To write the entire array, do

fwrite(writePlanet, sizeof(*writePlanet), totalSize, outFile)

assuming that totalSize is a number of entries to be written.

Same stays for read.

nezachem 616 Practically a Posting Shark

In the inner loop

while (wait1 < endwait) {

(lines 113 to 147) neither wait1 nor endwait ever change. You have to structure the loop similar to the outer one:

outer_loop_stop_time = clock() + outer_loop_run_time;
    while(clock() < outer_loop_stop_time) {
        inner_loop_stop_time = clock() + inner_loop_run_time;
        while(clock() < inner_loop_run_time) {
nezachem 616 Practically a Posting Shark

> Change sizeof(*s) to sizeof(struct ship) Care to elaborate what difference woud it make?

To OP:
The problem is that sort() parameters are struct ship * (disguised as void *), while you treat them as struct ship ** (notice the double indirection).

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

Few notes:
1. Child's stdout has been redirected to the pipe (line 21), hence don't expect anything on console.
2. Redirection (line 22) causes child to read from the writable end of the pipe.

nezachem 616 Practically a Posting Shark

The SUBDIRS variable contains a space. From make point of view, the line

make -C /lib/modules/2.6.38-8-generic/build SUBDIRS=/home/andrew/Documents/OS_Projects/Chapter 6 modules

means that SUBDIRS=/home/andrew/Documents/OS_Projects/Chapter , while 6 and modules are targets to make. You may either rename your directory to Chapter_6, or change your makefile to something like

$(MAKE) -C $(KDIR) SUBDIRS=\"$(PWD)\" modules

(untested)

nezachem 616 Practically a Posting Shark

MouseEvent (you are talking mouse events, right?) has methods AltDown(), ControlDown(), ShiftDown(), MetaDown()...

nezachem 616 Practically a Posting Shark

Looping while(!data.eof()) is incorrect. It causes one extra (unwanted) read, which in your case leads to a classic buffer overflow.

nezachem 616 Practically a Posting Shark

Do you see the difference between "should work" and "does"? The loop in sroot() starts with k = 1 no matter what. Only the final value is passed. You must pass an initial value as well.

nezachem 616 Practically a Posting Shark

Consider n==3.
The first call yields 1.
The second one yields 1+sqrt(2)
The third yields 1+sqrt(2)+sqrt(3)
Finally, you add them all together. Is that what you want?

nezachem 616 Practically a Posting Shark

> I do not think it is properly computing the sum.

Yes. But it has nothing to do with threads. The way you joining the threads means that nothing is running concurrently. Essentially you are calling sroot 3 times in a row, as in

sum = sroot(n/3) + sroot(2*n/3) + sroot(n)

and sroot calculates a sum of square roots from ... umm ... from what to what?

nezachem 616 Practically a Posting Shark

Yes, to remove a widget you'd do widget.grid_forget(). May we see the failing code (specifically, what is self in that context)?

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

It is disabled by default. Enable it with fsutil behavior set disablelastaccess 0 at the command prompt (as administrator of course)

nezachem 616 Practically a Posting Shark

Just for fun, do touch bin , and then run ./a.out / again. See that stat doesn't fail on bin anymore, yet it is presented as a plain file.
Can you explain this observation?

nezachem 616 Practically a Posting Shark

> dos based

Check out int86() function. Any compiler targeting dos shoud provide it. Int 13 is all you need.

nezachem 616 Practically a Posting Shark

I still don't understand your setup. Is there an OS involved; if so, which one?
And what exactly is a problem?

nezachem 616 Practically a Posting Shark

Let me rephrase. Is there an OS involved, or you need to go through BIOS, or directly drive the disc controller?

nezachem 616 Practically a Posting Shark

To be precise, an error must occur before any conversion took place. Errors in question are numerous. For a posix system, you may want to read an ERRORS section of man fscanf

nezachem 616 Practically a Posting Shark

Lines 50 vs 87-92. Make up your mind on bool vs char contents of Board[][].

nezachem 616 Practically a Posting Shark

How can we access hard disk addresses from c language, accessing ram address is easy? Also can we access MBR of NTFS through c , just a bit dissusion required for starting my work? Thank You All in Advance.....

It is very much OS specific. What exactly are you after?

nezachem 616 Practically a Posting Shark

You didn't initialize buf.priority (mtype in the msgsnd terms). msgsnd requires it to be positive, thus EINVAL. Adding

buf.priority = 2;

at around line 43 heals everything.
PS: Why 2? Because of 2 at line 76...

nezachem 616 Practically a Posting Shark

Run your program in a debugger. Set a breakpoint at line 32. Inspect the value of avgScore. Get surprised. Figure out why it is so.
If you don't know how to use a debugger, print avgScore after line 31.

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 lines 49-50, why do you index matches with i?

nezachem 616 Practically a Posting Shark

There is no solution with just functions. You need a macro, very similar in fact to offsetof.

nezachem 616 Practically a Posting Shark

Depends on how the executable (which you refer to as cpp) expects the input:
1. It reads the filename:

echo file1.xml | ./a.out > 3d-1.xml

2. It reads the contents of a file:

./a.out < file1.xml > 3d-1.xml

3. It takes a filename as an argument:

./a.out file1.xml > 3d-1.xml

All of the above presumes that a.out writes its output to stdout.

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

My recommendation is to sort of forget the most common and effective languages used in industry part, and study languages which represent the extremes of different programming models. It really gives a perspective on what software engineering is about. One possible set includes C, Forth, Haskel, Java, Lisp, Python, and Prolog. Coincidentally, (almost) no time would be wasted, since most of them are pretty much alive in the industry.

nezachem 616 Practically a Posting Shark

Sorry, a typo there. Missed -c:

$ stat -c '%Y' .
1317010317
$

The value is a modtime in seconds since epoch.
Still, which system are you using, and what exactly the manpage says?

nezachem 616 Practically a Posting Shark

What system is this? Also, can you quote more context from the man page?
Because normally to get a modtime one would call

stat '%Y' filename