nezachem 616 Practically a Posting Shark

Notice that sleep() delays the whole process (that is all threads are sleeping). It kind of defeats the purpose, don't you think?

nezachem 616 Practically a Posting Shark

This, in turn, means that there's no myprog.c file. I can't possibly know why. Check the spelling (including upper/lower case).

nezachem 616 Practically a Posting Shark

The only problem with the java implementation is that (besides being overdesigned) it wouldn't work in the OP situation: the bounds t to infinity.

nezachem 616 Practically a Posting Shark

A missing separator usually means that the rule line doesn't start with the tab. Make sure that there's no empty line between the dependency and the rule, and that the rule is indented with the tab - spaces do not work.

nezachem 616 Practically a Posting Shark

In your particular situation the condition is never going to be signalled. Just declare one in the pause() function, something along the lines of

void pause_thread(struct timespec * wakeuptime)
{
    pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
    pthread_mutex_t mx = PTHREAD_MUTEX_INITIALIZER;

    pthread_mutex_lock(&mx);
    while(pthread_cond_timedwait(&cond, &mx, wakeuptime) != ETIMEDOUT)
        ;
    pthread_mutex_unlock(&mx);
    pthread_cond_destroy(&cond);
    pthread_mutex_destroy(&mx);
}

This is a demo. Of course you may want to have cond and mx to be created once and destroyed once.
> just have limited knowledge when it comes to mutexes and conditions

That's OK. You want to learn, don't you?

nezachem 616 Practically a Posting Shark

>> CAn we trust wikipedia ?
> No.

Can we trust DaniWeb? The top 100 posters (that's 0.1% of the population) contributed 365917 posts (that's 25% of the post count).
An estimated contribution of the next hundred is at least 100000.

PS: The statistics page gives the top hundred. Is there a way to go down the list, and see the second, third, etc pages?

nezachem 616 Practically a Posting Shark

pthread_cond_timedwait() is a usual solution.

nezachem 616 Practically a Posting Shark

Excel statistical functions: TREND

The TREND(known_y's, known_x's, new_x's, constant) function is used to perform Linear Regression. A least squares criterion is used and TREND tries to find the best fit under that criterion.

Is that what you are looking for?

nezachem 616 Practically a Posting Shark

> just got the feeling
Then just try it. It wouldn't blow anything up.

> I dont really know how to count the delays and cycle
Back to my question 1.

PS: no matter if it works or not, it is a Very Bad Way to implement delays. Nevertheless, make it work, then we'll figure out something better.

nezachem 616 Practically a Posting Shark

Two immediate questions:
1. Why do you think it should work properly?
2. What makes you think it doesn't?

First question implies the environment (true 8088 vs emulation; where 6000h came from; interrupt state, clock frequency). The second implies, how do you measure the actual delay.

nezachem 616 Practically a Posting Shark

> Some compilers, such as GCC, automatically initialize integers to 0

Correction. No compiler initialize an auto variable to anything. Every compiler initialize static variables to 0 (this is mandated by the Standard).

> issue a warning
At a proper warning level GCC will issue a warning as well.

nezachem 616 Practically a Posting Shark

In your second script the N command does join a current pattern space with the next line; however the s command causes the (updated) pattern space to be printed out. Essentially, you join pairs of lines.

My recommendation would be to use a hold buffer, and careful addressing like this:

/PowerOnHours/ !{
    # Notice the negation. Any line not matching is appended to the hold buffer
    H
}
/PowerOnHours/ {
    # Got the end of record. Append it to the hold buffer...
    H
    # ...copy the hold buffer into the pattern space...
    g
    # ...replace newlines with tabs...
    s/\n/^I/g
    # ...print out the desired result
    p
    # Finally, clear the pattern space and place an empty line in the hold buffer
    # for the next iteration.
    s/.*//
    h
}
nezachem 616 Practically a Posting Shark

> would shifting 0x01 to the left

Very solid approach.

nezachem 616 Practically a Posting Shark

> Are you trying to toggle the signed bit and shift?

If the question is for me, the answer is no. I am shifting the sign bit alone. It is the first step to get the right mask.

nezachem 616 Practically a Posting Shark

> lets say the number is 110001000100 and n is 2...
... so after the shift it becomes 111100010001, and you need to get rid of the 2 leading ones, right? Hint: what happens if you shift 100000000000 right by one (that is, by n - 1)?
I didn't see a subtraction among the legal operation. If it is the case, shift it right by n, and then left by one.

nezachem 616 Practically a Posting Shark

Two problems with the code. An immediate and major one is that

char writefile[1000000];

attempt to allocate one million characters (that is one megabyte) on the stack. The stack is a very limited resource. For example, Windows by default gives one megabyte for the whole stack, and by the time your function is called part of it is already in use. No wonders you have a stack overflow. Never ever allocate large objects in automatic storage.

Problem number two is

void writefile()
{
	char writefile[1000000];

Giving a function and a variable same names may or may not cause a headache to a compiler. It certainly causes one to a reviewer.

> I tried the code below and it worked.

This is probably the most unprofessional way to answer the question.

nezachem 616 Practically a Posting Shark

First, the formal answer. Quoting the Standard,
output shall not be directly followed by input without an
intervening call to the fflush function or to a file positioning
function (fseek, fsetpos, or rewind), and input shall not be directly
followed by output without an intervening call to a file positioning
function

Your program satisfy the first requirement - you have fsetpos() between fgets() and fwrite(), but violates the second one - there's nothing between fprintf() and the next fgets() (note that fgetpos() is not a file positioning function).

Such a violation causes an undefined behaviour, which means that the program may occasionally work as expected, but not required to. The exact reason why did it work is unclear; I may only speculate that it has something to do with the underlying buffer sizes: your home system and the university server are configured differently.

The guts of the problem are with the IO buffering. I am afraid I can't explain "in depth" and stay in the format of a forum post.

nezachem 616 Practically a Posting Shark

Add fflush() right after fprintf(). Quoting man fsetpos:
The fsetpos() function shall fail if, either the stream is
unbuffered or the stream's buffer needed to be flushed, and the call to
fsetpos() causes an underlying lseek() or write() to be invoked

nezachem 616 Practically a Posting Shark

> Am I doing it wrong?
Yes.
Initialize vg once for the m you need.
To get a random number, instead of rand()%m just call vg().

nezachem 616 Practically a Posting Shark

I still do not understand: how desctop_pc.start() is called in this scenario?

The applet is PcLab. The PcLab.init() creates two new desctop_pc. At this moment nobody cares that desctop_pc is an instance of Applet; it doesn't matter if is has or has not a start method. The desctop_pc() constructor immediately spawns a thread, which enters the run().

So, what is a code path to desctop_pc.start()?

nezachem 616 Practically a Posting Shark
<applet code=PcLab.class width=900 height=200>

This is PcLab.start():

public void start (){
  // desktop_pc PC1 = new desktop_pc();
  // desktop_pc PC2 = new desktop_pc();
  
   buffer.append(" Start1 ");
   repaint();
}

This is what the OP wanders about:

I am expecting to see the string displayed on my browser window "inside desktop_pc , run method". But I dont see this happening.

(cf desctop_pc.start())

nezachem 616 Practically a Posting Shark

To be precise: start() is not an interface method for Runnable. It is a Thread method. Invoking thread.start() results in spawning the thread and executing the Runnable's run() method in it.
Since you are not extending Thread (which I wouldn't recommend to do), the call at line 68 does not relate to the start() method at lines 72 and below; this code is never execuetd.

nezachem 616 Practically a Posting Shark

Hint: You don't need to calculate hexagonal numbers. You just need to test if a given number is hexagonal. In other words, find out if the equation
x*(2*x - 1) = P(i)
has integer roots.

jephthah commented: here, have some bling +9
nezachem 616 Practically a Posting Shark

> changing the size of the array

This is right. In your original code you were trying to allocate 4 megabytes of data on the stack. The default stack size is 1 meg.

nezachem 616 Practically a Posting Shark

The most immediate problem is on lines 14 and 28; the local definition of catalogue shadows the global definition (didn't you get a compiler warning?). I am not sure what exactly happens, but it is pretty much possible that you sort one array, and print another. For example, appendEntry surely fills up the global one; which one is passed to qsort, I have no idea. Verify it with the debugger.

On a side note, your sorting setup is incorrect. You want to sort only rep records, not the whole array.
On another side note, why are you redeclaring qsort? It is already declared in stdlib.h.

nezachem 616 Practically a Posting Shark

> Everything posted is fine.

You sure?

int grade1 = 0;
	char grade1 = 'A';    // this is where it fails
nezachem 616 Practically a Posting Shark

Umm... they are tokens.

nezachem 616 Practically a Posting Shark
printf("%d %d %d\n",a=10,a=20,a=30);

> expression statements separated by commas

This is not a comma expression - this is an argument list. They look very similar, but they are really different creatures (think about this: the comma expression yields just one value). In the argument list case there's no guarantee in which order the arguments are evaluated.

nezachem 616 Practically a Posting Shark

> But which character has the ASCII value of 0XFF is -1

The stream you are reading is not necessarily textual. getchar() must read any data.

nezachem 616 Practically a Posting Shark

> are outside the definition of tokens
No. The Standard defines token as either of:
keyword
identifier
constant
string-literal
punctuator
and punctuator in turn is either of
[ ] ( ) { } . ->
++ -- & * + - ~ !
/ % << >> < > <= >= == != ^ | && ||
? : ; ...
= *= /= %= += -= <<= >>= &= ^= |=
, # ##
<: :> <% %> %: %:%:

nezachem 616 Practically a Posting Shark

os.walk returns the filenames without the path prefix. That is, you are trying to open them in the current directory, where they do not exist. change line 7 to

f = open(os.path.join(subdir, file), 'r')

PS: your variable names are misleading.

nezachem 616 Practically a Posting Shark

At line 10 you open a file as prompted. At line 16 you immediately discard the result and open another file, which name is given as a command line argument. Which one do you really want?

PS: if the command line has no arguments, the result is pretty much undefined.

nezachem 616 Practically a Posting Shark

Sorry if I sound too US-centric.

In the USofA, nothing is legally certain unless the judge rules on it. The GPL has been tried several times in the court of law, but each case yet has been settled. No ruling has been produced. That is, nobody knows what exactly does the GPL mean (there was one case which outcome was that GPL does mean something).
Most experts agree that linking a GPLed library dynamically doesn't force the "main" code into GPL. The reasoning is very convincing... but anyway no court ruled on it.

In my opinion, it is OK to close source the GPL-linked code, provided you have guts to go all the way to the Supreme Court. The open source community will be eternally thankful for cleaning up the mess.

jonsca commented: Interesting... +7
nezachem 616 Practically a Posting Shark

>> Yes, I am well aware that this is the C forum, not C++. I don't have a copy of the C standards but I'm certain it contains the same or similar verbage.

> It does not

PS: This is the it.

nezachem 616 Practically a Posting Shark

> Yes, I am well aware that this is the C forum, not C++. I don't have a copy of the C standards but I'm certain it contains the same or similar verbage.

It does not.

C++ has a good reason to restrict main. It is not applicable to C.

nezachem 616 Practically a Posting Shark

Any, as in all, or any as in at least one?

Disclaimer: as I said above, no test constitutes the proof. My claim may only be disproved by the relevant chapter and verse of the Standard. However, the test is here.

The following compiles with the warning (and runs as expected) with gcc. I don't know if this warning is mandated.
MSVC compiles it with the warning 'static qualifier discarded', obviously failing to link. I suspect that MSVC behaviour is not compliant.

$ cat main.c

extern int foo();

int main(int argc, char ** argv)
{
    foo();
    return 0;
}

$ cat foo.c

#include    <stdio.h>

static int main()
{
    printf("static main\n");
    return 0;
}

int foo()
{
    main();
    return 0;
}

$ gcc -Wall main.c foo.c
foo.c:4: warning: ‘main’ is normally a non-static function
$ ./a.out
static main

$ gcc -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: /var/tmp/portage/sys-devel/gcc-4.1.2/work/gcc-4.1.2/configure --prefix=/usr --bindir=/usr/i686-pc-linux-gnu/gcc-bin/4.1.2 --includedir=/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include --datadir=/usr/share/gcc-data/i686-pc-linux-gnu/4.1.2 --mandir=/usr/share/gcc-data/i686-pc-linux-gnu/4.1.2/man --infodir=/usr/share/gcc-data/i686-pc-linux-gnu/4.1.2/info --with-gxx-include-dir=/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4 --host=i686-pc-linux-gnu --build=i686-pc-linux-gnu --disable-altivec --enable-nls --without-included-gettext --with-system-zlib --disable-checking --disable-werror --enable-secureplt --disable-multilib --enable-libmudflap --disable-libssp --disable-libgcj --with-arch=i686 --enable-languages=c,c++,treelang,fortran --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu
Thread model: posix
gcc version 4.1.2 (Gentoo 4.1.2 p1.1)
nezachem 616 Practically a Posting Shark

> All of the 32bit tutorials

Looks like you missed this, which accidentally comes first on a protected mode screen access google search.

nezachem 616 Practically a Posting Shark

// this appears to be causing the trouble

No. It is line 9. The error message points to line 17. There you call read with no arguments, while the definition of ReadIn.read requires one.

Bladtman242 commented: Provided excatly what i needed. +3
nezachem 616 Practically a Posting Shark

Sorry, you are all wrong. You may have as many mains as you want, provided they are all static (except one, of course). I am not even talking about dll tricks.

> there is nothing like a good test

Not for the questions like this. Language is defined not by the implementation, but by the standard. Tests could be wrong. Compilers could be non-compliant. Standard is flawless. It takes a language lawyer to answer them though.

nezachem 616 Practically a Posting Shark
int input(worker_t *);
...
worker_t foo;
input(&foo);
...
worker_t employee[10];
input(&employee[5]);
input(employee + 5);
nezachem 616 Practically a Posting Shark

> if it contains a loop, i.e is a circular linked list

Not exactly. The loop not necessarily includes the head (consider 1->2->3->2). In that case your algorithm will run forever.

The solution takes two pointers traversing the list with different "speeds":

pointer1 <- head
pointer2 <- head
do:
    pointer1 <- next(pointer1)
    pointer2 <- next(next(pointer2))
until 
- either one of the pointers hits the end of list (not a loop)
- or pointer1 becomes equal to pointer2 (loop detected)
nezachem 616 Practically a Posting Shark

> So I'm porting a bunch of C functions that manipulate packets

Now that's a completely different story. Did you consider JNI? From the validation and maintenance standpoint I'd prefer to have a few interface entries to the existing C code, rather than porting everything.

VernonDozier commented: Thanks for the tip. +13
nezachem 616 Practically a Posting Shark

> Why did they make Integer non-mutable?

Hard to say; my wild guess is to make it possible to use Integer as a key in a hashtable, etc.

nezachem 616 Practically a Posting Shark

My question is why do we even need AtomicInteger.

It is not about mutability. An Atomic prefix suggests that its methods are sefe in the multithreaded environment without additional synchronization.

nezachem 616 Practically a Posting Shark

I explained why. Please reread my post. After that, please answer (in plain English, no code)
- how do you want the loop to terminate, and
- how does it actually terminates.
Then we can proceed.

nezachem 616 Practically a Posting Shark

> I don't see why the function has to be so complicated..

Mostly because it reverses characters in the string, not the words. But it is a good start. Once the characters are reversed, you can apply the same function to each individual word, and reach the goal.

nezachem 616 Practically a Posting Shark

> gives error that undefined reference "exp"

Including math.h is not enough. You need to link with the actual math library. How exactly do that depends on your compiler. Check the documentation.

nezachem 616 Practically a Posting Shark

Code tags!

org $4000
Alph equ 26 26 Alphabets

begin:
    lea LC,A0 store lowercase to A0
    lea UC,A1 store uppercase to A1
    move.b #Alph,d1
    sub.b #1,d1

loop:
    move.b (A0)+,d0 convert LC to UC
    sub.b #32,d0
    move.b d0,(A1)+
    dbra d0,loop goes back to loop

    move.b #9,d0
    TRAP #15


org $4100
LC dc.b 'computer hardware' define lowercase

org $4200
UC ds.b 26 reserve for uppercase
END begin

To terminate the loop you are using D0. It has a value of whatever has been loaded by mov (at line 11) less 32. Coincidentally, the ascii code for a space is 32. As soon as your program hits the space, the D0 value becomes 0, which breaks the loop.
Obviously, you want to control the loop by another data register; from what I see in your code, you tried to set up D1 for that purpose. The immediate question is why do you initialize it the way you do?
PS: you need some logic to convert only lowercase symbols.

nezachem 616 Practically a Posting Shark

Line 48:

node *newnode;

node is just a pointer, which points nothing in particular. Trying to dereference it may result in any strange consequences imaginable. You need to initialize it with

node *newnode = new node();

Regarding a temp nodes in other functions, you should initialize them as well, but in a different manner:

node *temp = head;

Can you see the difference and the reason why they are different?

nezachem 616 Practically a Posting Shark

Try perror instead of printf. That will give you a more hintful error message.