nezachem 616 Practically a Posting Shark

MS-Windows does not support shared memory segments

In fact, it does, since at least XP.

Ancient Dragon commented: right :) +17
nezachem 616 Practically a Posting Shark

I suspect the OP problem is much simpler; it is a purely logical error. Opon the first loop completion, classInfo is the value of the last qualifying trainClassInfo. The second loop always runs all the way through, and the last comparison always evaluates to True.
Solution: exit the second loop as soon as the mismatch is detected.

nezachem 616 Practically a Posting Shark

A google search on alsa api returns many useful links. I am not familiar with Windows/C# audio model, so I don't know how well it is mapped onto alsa.

Regarding joystick, it is seen by the system as a serial device; you need to open it, query it with some ioctls (JSIOCGAXES and JSIOCGBUTTONS), and then just read struct js_event (see linux/joystick.h for reference).

jbennet commented: fairly helpfulish +15
nezachem 616 Practically a Posting Shark

There's no boolean in C. Any incarnation of zero resolves to false; everything else resolves to true. !fork() is therefore synonymous to fork() == 0

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

If you mean lines 79-82, the logic is as follows: p_clause is declared as struct __clause ** . *p_clause is struct __clause__ * , that is, a pointer. sizeof(*p_clause) yields the size of pointer (most likely, 4), regardless of how much memory you did allocate.
Do realize that (1) sizeof is calculated at compile time, and (2) there's now way to determine a size of object pointed to by inspecting the pointer.

Regarding a segfault, line 77 screws you up. The intention was to restore the *p_clause to its original value after it's been modified by the loop, right? But the loop doesn't modify it.

nezachem 616 Practically a Posting Shark

The argument is passed by the OS when the signal is delivered. The rationale is that you may install the same handler for different signals.

nezachem 616 Practically a Posting Shark

A wild guess: you are running on Windows, right?
The png file begins with a signature
ID=89h,'PNG',13,10,26,10
which contains a byte with a decimal value 26, that is ascii Ctrl-Z, which is an end-of-file for a text mode. Open your file with "rb" instead of "r" and enjoy a garbage on your screen.

nezachem 616 Practically a Posting Shark

Just wonder what does it print at line 23... Do you realize that 10^100 takes 30+ bytes as an integer?

For the rest, read the math.

nezachem 616 Practically a Posting Shark

So now we agree that gdc works fine, and a problem is somewhere else.Correct me if I am wrong, but there's nothing in your code which would assign any value to firstRandomNumber (or secondRandomNumber). I am talking about the shared global variables, declared at lines 18 and 19.

PS: didn't your compiler warn you that a formal parameter shadows a global declaration?

nezachem 616 Practically a Posting Shark

> First of all, assuming your binary string is stored from most significant bit to least significant bit, you will have to traverse it in reverse

No no no. Direct traversal is much simpler. Two methods need to be implemented: double a decimal string and add a bit value (0 or 1) to a decimal string.

In a pseudocode,

initialize a resulting decimal string
for each "bit"
    double_decimal_string
    add bit value to a decimal string

double_decimal_string
    set carry to 0
    for each digit in a string
        double digit
        add carry
        if result > 10
            subtract 10
            set carry to 1
        else
            set carry to 0

> I'm sure there a sequences like that for other digits too!
I seriously doubt that.

mike_2000_17 commented: nice and simple, I like it! +11
nezachem 616 Practically a Posting Shark

> There was something wrong with my http request (changes are on line 75 and 76)

Yes. You shouldn't split those two lines. The correct request is
GET / HTTP/1.1\r\n
\r\n
At the 1.1 level this is not enough. You must send additional headers, such as Host (I don't recommend using 1.1 until you master 1.0 level).

When receiving a response, do not expect to get everything in a single recv call.
Finally, do not send all 100 bytes of aa . There's a lot of garbage there.

nezachem 616 Practically a Posting Shark

Few problems in your code.
First, your pops are in a wrong order. The last thing pushed shall be first to pop.
Second, can you explain line 105? The way it is written, you are (a) jailed to state_1 and (b) bound to a stack overflow.

nezachem 616 Practically a Posting Shark

The behaviour you describe means that a -I option is silently passed to rm. Usually it is done by aliasing rm to rm -I somewhere in the startup scripts; some people think it is a good idea. The simplest way is to directly invoke /bin/rm instead. If you are writing a script, a full path to an external executable is a must anyway. If you are just annoyed at the command line, search your startup scripts for rm, and comment out the aliasing.

nezachem 616 Practically a Posting Shark

You can't send std.string to fscanf. It expects a C-style character array.

Akill10 commented: thanks +1
nezachem 616 Practically a Posting Shark

It is (almost) beyond the programmatic control. The backspace character is processed by the console driver and not delivered to the program. You may prepare the file with embedded backspaces and redirect input from it; this way the driver is bypassed, and you will see the "\b".

nezachem 616 Practically a Posting Shark

I think we all attempted to understand the question. I don't think this is the type of question that any of us are used to hearing around here.

I suppose I was overly harsh. I expected that problems of this kind are too well known. My apologies.

Whether that's a good skill to have is probably debatable.

Agree 99%. The remaning 1% of disagreement is that this skill is undebatably bad.
A K&R1 language definition was obsoleted just to avoid such abuses.

nezachem 616 Practically a Posting Shark

Wrong. When asked for clarification, he regurgitated the requirements originally posted. Since I quoted them, I already knew them, and stated I did not understand them. To repost them was a complete waste of time and utterly worthless. They are now posted in the thread at least 4 times. By your disagreement you are stating "the more times you post the same information the clearer the information becomes. Good luck with that.

Let's go through the logics, because you definitely lost me.
There was a statement: Information was asked for, and it was not provided
to which I disagreed by saying: Information was provided.
Can you clarify how does it come to the more times you post the same information the clearer the information becomes.?

nezachem 616 Practically a Posting Shark

> Information was asked for, and it was not provided

May I respectfully disagree. If you ever participated in those stupid contests, you'd immediately realize what the OP is asking for. That said, OP doesn't seem to do it either.

Now I am going to play an advocate. All the information is here in the thread.
For example, Twice x="%d" has been mentioned was answered even before the question was asked: Warnings are not to be considered. That is, a code should comply to K&R spec, so x shall be treated as an extern int, and a warning of char*-to-int cast is irrelevant.
Same goes for reuse of char** arguments of main as ints.

The question asked was not "how can I make it compliant", and not even "what's wrong with it", but "how to reduce it". Nobody even attempted to understand the question, except Adak.

nezachem 616 Practically a Posting Shark

I do not. Making a good compiler is very difficult indeed, but I can name few tasks much more difficult.

WaltP commented: Like answering question with the details give in many of these threads. +16
nezachem 616 Practically a Posting Shark

Stare at lines 52 and 87 of symbol.cpp until an enlightenment descends on you.

nezachem 616 Practically a Posting Shark

> how do i check ?

A preferred way is to set a breakpoint there.

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

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

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

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

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

// 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
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

> 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

First of all, both arrays must have the same size - they represent the same tree, so they have exactly as many elements as there are nodes in the tree. No need to test both sizes.
Second, in the terminating situation you should return NULL, not the root.

Third, there are way too many problems with the implementation.

You determine the array size with strlen(). This is wrong in general, because it restricts you to zero terminating strings (it also kills the asymptotics, but for now it's a least of the worries). This is wrong in particular, because the copies you made are not zero terminated.
The simplest way around - which also happens to be a correct solution - is to pass the size as a third parameter to plantBTree.

The copies themselves are also made incorrectly. For example,the RSTp loop fills up the right part of the array - leaving the left one with garbage. That garbage is then passed down to the recursive call. You need to pass RSTi + PreorderIndex + 1, RSTp + PreorderIndex + 1 instead, or copy to the beginning of the RST arrays.
Now, with the size being passed separately, copying doesn't buy you anything, and just stands in the way. You shall work directly from the original arrays. Hint: the whole function fits into 10 lines or so.

A final note: get rid of the global variables. They are bad in general, and extremely …

nezachem 616 Practically a Posting Shark

Another hint: take the differences of your sequence (that is, f(n) - f(n - 1)). You will see the pattern very clearly.

nezachem 616 Practically a Posting Shark

The variable is just some (named) piece of a computer memory. It always has a value. Before you assign something to it, the value is garbage: useless, unpredictable, yet a value. This is why initialization is so important. Fix your program by initializing:

int smallest = INT_MAX;
nezachem 616 Practically a Posting Shark

Typo correction: a 16-bit register may contain data in the range of 0..65535; 255 is a maximal value of an 8-bit register.

Ancient Dragon commented: right +35
nezachem 616 Practically a Posting Shark

Here's a fairly crazy proposal:
Pipe your files through sed -e 's/^#include/INCLUDE' prior to gcc -E, and then back through sed -e 's/^INCLUDE/#include/' (all that assuming that you don't want to expand any of your includes, and no line in your code begins with INCLUDE; in any case, the sed command could be tailored according to your needs). This is very much ad hoc, but I doubt there is a clean solution..

nezachem 616 Practically a Posting Shark

1. The compiler sees the call to getdet at line 4. It has to assume something about this symbol. The assumption is that it is a function returning int. At line 6 it sees that getdet is a function returning a pointer. This mismatches its previous assumption. Warning is emitted.
To avoid the warning, you have to be explicit: add a declaration

short int ** getdet (short int **m , int n);

above main.

2. You are trying to calculate a determinant - why returning the pointer at all?

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

Few problems here.
1. Design problems.
1.1 You declare the function as void, yet in some cases return a value. Make up your mind (should I write a function like this, I'd declare it int and return the file descriptor).
1.2 The function opens just one file; therefore it needs just one argument. Yet you pass it the whole (counted) array of them.
That is, the proper declaration should be

int outputFile(char * filename)

2. Implementation problems.
2.1 A stat/open combination is a race condition (imagine another process creating the file right in between of a (successful) call to stat and a call to open). Don't do that.
Besides, it is redundant, because O_CREAT | O_EXCL flags do force open to fail if the file exists.
2.2 Error message at line 17 is not informative.

3. Too many unnecessary (and even undeclared) variables. What is inode, what is i?

All that said, the function becomes

int outputFile(char * filename)
{
    int file_desc_out = open(filename, O_CREAT | O_WRONLY | O_EXCL , S_IRUSR|S_IWUSR);
    if (file_desc_out == -1) {
        perror(filename);
    }
    return file_desc_out;
}
nezachem 616 Practically a Posting Shark

It links in the librt.so, the library which provides (among other things) implementation of the sem_* functions. Ask me not why this library is called rt; however, see the Linking section of a sem_overview manpage.
PS: it is important to realize that sem family is not related to pthread family whatsoever. The fact that posix semaphores, pthreads (as well as System V primitives) coexist peacefully in the same system is one of the marvels of unix.

nezachem 616 Practically a Posting Shark

> gcc filename.c -lpthread
is not enough. You also need -lrt

nezachem 616 Practically a Posting Shark

inotify is what you are looking for.

nezachem 616 Practically a Posting Shark

would something like this be better?

A step in the right direction, for sure. In the updated version you can easily identify the Factory, and factor it out, for example:

int main()
{
    while(true) {
        subsystem = Subsystem::open();
        subsystem.execute();
        delete subsystem;
    }
}

The static open() method deals with the user input and instantiates the proper object.

nezachem 616 Practically a Posting Shark

This could be helpful.

nezachem 616 Practically a Posting Shark

I agree that the code is not polished. I disagree though with the proposed "encapsulation of ifs". Your approach requires 25 comparisons for each non-accented letter - just to leave it alone. Really wasteful, isn't it?

Consider a redesign based on a lookup table. Such table indexed by the original character, with the value being a the substitution one. For example, translate[0x83] is 'a', translate[0xc6] is also 'a', etc. This way the code collapses to a short simple loop:

for(x = 0; x < strlen(texto); x++)
        text[x] = translate[texto[x]];

Of course, you need to put some extra effort to populate the translation table.

nezachem 616 Practically a Posting Shark

char args[7][50] and char * args[7] are completely different creatures. The former is an array of 7*50 characters, while the latter is an array of 7 pointers.

A function foo taking char args[7][50] would have have a signature foo(char[][50]) ; it is vital to know the width of such array to work correctly. There's no way to pass such information to a function of exec family. You must hand them an array of pointers. For example,

char * real_args[7];
    real_args[0] = args[0];
    real_args[1] = args[1];
    // etc;
    execvp("compute", real_args);
nezachem 616 Practically a Posting Shark

Closing the listening socket is a right way to go. Then accept() returns -1 and sets errno to EBADF, as you already observed. You just need some more logic in the "threading stuff" to analyze what have actually happened. For example, test not_ended: if it is false, you know for sure that the error is intended, and that the shutdown is in progress; otherwise you may want to do whatever recovery is necessary, and restart the listener.

nezachem 616 Practically a Posting Shark

You did it backwards. msgctl copies data from the buf to the kernel space. So, you need to modify BUF with the desired values, and then call msgctl.

Keep in mind that BUF as it is contains garbage. Before any other operations fill it up with the correct values via IPC_STAT.

a-humam commented: well and fast answer +1
nezachem 616 Practically a Posting Shark

The problem is with parent closing the write ends too early, so that the corresponding file descriptor is reused in the next pipe() call; bottom line is, at the read() time parent attempts to read from the closed descriptor.
Comment out lines 28-29 and see for yourself.

PS: always test errno after every system call.
PPS: I don't know how to debug a child in eclipse.

rafi1082 commented: helped me solve a bug +0
nezachem 616 Practically a Posting Shark

Do svn add images first. Then svn commit images .