636 Posted Topics
Re: 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 … | |
Re: Line 48: [CODE] node *newnode;[/CODE] 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 [CODE] node *newnode = new node();[/CODE] Regarding a temp nodes in other functions, you should initialize them as … | |
Re: [B]> Would a "sparse" check of just those file descriptors (using a set iterator) in the set be ok to use?[/B] Absolutely OK. | |
Re: The url3 has too many % signs. The %20e sequence tries to format an argument as a floating point into 20 characters. Change stray %s into %%s: [ICODE]Authority%%20eq%%20'%s'&$inlinecount[/ICODE] | |
Re: Because it is an integer division. 3/2 yields 1, not 1.5 | |
Re: Arguments for strcmp must be terminated with 0. Your wordone and wordtwo are not: they are arrays of 4 characters, and all four are filled up with input. The trailing garbage they have is different thus causing strcmp to report inequality. | |
Re: Please post some more details: - How does it crash? - Does the executable have debug information? - Do you have sources? - What does [ICODE]ulimit -c[/ICODE] report? | |
Re: The code you suggested leads to the race with a high chance of a deadlock: [CODE] write(fd[WRITE_END], write_msg, strlen(write_msg) + 1); while (read(fd[READ_END], (char*)&ch, sizeof(char)), ch != '\n') { ... }[/CODE] Here the parent would immediately read back whatever it just wrote, eventually leaving both processes hung at the read(). … | |
Re: [B]> So I was wondering if I am doing this right?[/B] Certainly not. The mux has 8 data inputs, and 3 control inputs. Remember that the 3 bits of control represent a number from 0 to 7. The number is the index of the input which should be copied to … | |
Re: Another hint: take the differences of your sequence (that is, f(n) - f(n - 1)). You will see the pattern very clearly. | |
Re: [B]> Pragma once is suppose to help, no?[/B] No. Pragma once only helps against multiple inclusions into the same translation unit (read, same .cpp file), that is, at the compilation time. Your situation is different: Average Calculator.cpp and PaintHandler.cpp both independently include Average Calculator.h; they are both independently compiled, and … | |
Re: Line 95: you are copying an original array on top of what you just calculated. You want it other way around. | |
Re: [B]> why the compiler(gcc) outputs a warning[/B] Because your main is (correctly) declared as returning int, but does not actually return anything. | |
Re: Read the documentation carefully. You manage to violate practically all restrictions for the out instruction: [CODE]out Output (write) to port Syntax: out op, AL out op, AX op: 8-bit immediate or DX Action: If source is AL, write byte in AL to 8-bit port op. If source is AX, write … | |
Re: 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: [CODE]int smallest = INT_MAX;[/CODE] | |
Re: Few problems here. First, there's only one struct employee allocated (line 4), and would be written over and over with each new record. Second, I said "would be" above, because &emp in the fread is wrong; it should be just emp. Can you see the difference? Third, it is very … | |
Re: The semicolon at line 15 means that the code actually is [CODE]while (( n = fread(buffer,1,sizeof buffer, original_pointer)) > 0) /* Do nothing */ ; /* End of loop */ { fwrite(buffer,1, n , copy_pointer)[/CODE] and fwrite is called once, after the loop finished, with n equal to -1. Also, … | |
Re: Your server closes new_socket after each message it receives. Your client, on the other hand, sends all its messages over the same socket. That is, the second message is sent through the socket which is already closed. Therefore, the crash. Rethink your design. Either let the client reestablish connection for … | |
Re: [B]> Try to open it for reading. If it opens, it exists. [/B] This approach suffers an inherent race condition. Moreover, in most cases (including this) such test is redundant. Both windows and posix systems provide an atomic solution to the OP problem. For windows it is CreateFile with the … | |
Re: This is just one of the issues, and you are definitely made a correct move. Now, the 'c' object in c.execute() is undefined (you have conn, you have cursor, but what is c?). The fact that python doesn't complain means that the c.execute line is never actually executed. It means … | |
Re: Unless using awk is mandatory, I'd recommend using [icode]join[/icode]. | |
Re: 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. | |
Re: [ICODE]strcat[/ICODE] (at line 31) doesn't work well with binary contents. | |
Re: The standard recommendation is to replace all the windows style paths with cygwin paths, such as /cygdrive/d/FRODAN/whatever. make dropped support for windows style paths since at least 2006. | |
Re: You don't want to deal with interrupts, unless you are in an OS-less environment. For Windows, read [URL="http://www.codeproject.com/KB/system/HwDetect.aspx"]this[/URL]. | |
Re: It is very important to understand that an application and the kernel reside in different address spaces. It means, among other things, that the application possibly cannot call anything in the kernel; the only way to "call" it is through the syscall mechanism, which essentially is the interrupt. This answers … | |
Re: Here's a fairly crazy proposal: Pipe your files through [ICODE]sed -e 's/^#include/INCLUDE'[/ICODE] prior to gcc -E, and then back through [ICODE]sed -e 's/^INCLUDE/#include/'[/ICODE] (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 … | |
Re: 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. … | |
Re: 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 … | |
Re: [B]> I calculated that this function gives the number of sequence that sums to a number n[/B] I seriously [URL="http://en.wikipedia.org/wiki/Partition_%28number_theory%29"]doubt[/URL] that. | |
Re: Always test the return values of the system calls. In this case, is ShmID valid? What is errno after shmget? What is errno after shmat? | |
Re: [URL="http://dell9.ma.utexas.edu/cgi-bin/man-cgi?inotify+7"]inotify[/URL] is what you are looking for. | |
Re: [B]would something like this be better?[/B] A step in the right direction, for sure. In the updated version you can easily identify the Factory, and factor it out, for example: [CODE]int main() { while(true) { subsystem = Subsystem::open(); subsystem.execute(); delete subsystem; } }[/CODE] The static open() method deals with the … | |
Re: 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 … | |
Re: [URL="http://www.christian-seiler.de/projekte/fpmath/"]This[/URL] could be helpful. | |
Re: Look at line 26. Anything suspicious there? | |
Re: 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 … | |
Re: [ICODE]char args[7][50][/ICODE] and [ICODE]char * args[7][/ICODE] are completely different creatures. The former is an array of 7*50 characters, while the latter is an array of 7 pointers. A function [ICODE]foo[/ICODE] taking [ICODE]char args[7][50][/ICODE] would have have a signature[ICODE]foo(char[][50])[/ICODE]; it is vital to know the width of such array to work … | |
Re: Search this forum for why using eof() is not a right way to control the read loop. [CODE]do { mystream.getline(line, 100); mystream >> country_name >> happiness_value; total_happiness = total_happiness + happiness_value; count++; outputstream << country_name << " \t \t " << happiness_value << endl; } while (!mystream.eof());[/CODE] In short, to … | |
Re: 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 … | |
Re: In the circular queue you may not rely on relative head and tail positions. You must keep track of the number of elements manually. Extend the struct queue with an int count initialized to 0. Increment it on every enqueue and decrement on every dequeue operations. Rewrite is_empty and is_full … | |
Re: [B]> of maybe using pointers[/B] Wouldn't help. A compiler is smart enough to do that for you. In fact, any code-level optimization will gain you very little. Looks like you are multiplying matrices. Strasser algorithm is a way to go. | |
![]() | Re: 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 … ![]() |
Re: Do [ICODE]svn add images[/ICODE] first. Then [ICODE]svn commit images[/ICODE]. | |
Re: firstnode never changes. AddToList is passed the _value_ of firstnode (which is NULL), and operates on the local variable. Upon return, firstnode remains NULL. You have to either pass an address of firstnode, [CODE]void AddToList(LankadLista ** listaptr, char name[]) { ... *listaptr = newnode; ... } main() { ... AddToList(&firstnode, … | |
![]() | Re: It is important to realize that the child process cannot possibly affect the parent's environment. When you run the command from the executable file, a second copy of bash is forked, it has its environment changed and then dies leaving no trace. The builtins (dot and source for example) are … |
Re: Most likely, it is dying at line 32. You have to allocate writable memory for the whole backup filename. | |
Re: The entry returned by readdir is statically allocated. That is, you end up with only one instance of it, and all the pointers in the files array will have the same value. You need to hold each d_name individually: replace line 41 with [CODE]files[count] = strdup(entry->d_name);[/CODE] |
The End.