389 Posted Topics
Re: The only `return true` is your code is on line 5. That line is inside the `each`, so it can only be reached if the array is not empty (otherwise the code in the `each` does not execute at all). If the array is empty it goes directly to line … | |
Re: The only statement inside your for-loop is `prod = prod*even;`. The others are outside of the loop. The braces around your for-loop do not affect what's inside the for-loop - they only introduce a new local scope. To affect the extent of the for loop, the opening brace should be … | |
Re: `<` is the input redirection operator in the shell. When you write `java SetTest < Ted.txt`, you're executing the command `java SetTest` without passing any arguments to `SetTest` and feeding Ted.txt into the program's standard input stream. This is not possible to do in Eclipse. If you want to read … | |
Re: `{0}` and `{1}` are placeholders for the second and third arguments to `WriteLine` respectively. So `{0}` is replaced with the value of `n` (the second argument) and `{1}` is replaced with the value of `Fib(n)` (the third argument). So `Console.WriteLine("F({0}) = {1}"**, n, Fib(n))` will print `F(3) = 6` when … | |
Re: > pass in the arrays as references: `int Checker(char *s,char *u)` The signatures `int Checker(char s[], char u[])` and `int Checker(char *s, char *u)` are 100% equivalent. It is not possible to pass C arrays by value. Also note that `s` and `u` are pointers, not references. A reference to … | |
Re: There is one situation where that line could cause a segmentation fault by itself: a stack overflow. If your stack grows beyond the size it's allowed to have and `index` is the first variable that you assign to whose address is outside of the legal bounds of the stack, then … | |
Re: Where and how are you using `NewLine`? If you replace your use of `NewLine` with `std::endl`, does the error disappear? If so, that would kind of surprise me to be honest. If not, your problem has nothing to do with the fact that you defined NewLine as a macro. Also … | |
Re: > why it the program won't stop until the 3 variable is already greater than 70?? Because your while condition says the the program should loop while either of the variables is less than 70. Let's say your variables are a=77, b=70, c=67. Is the statement "a is less than … | |
Re: > don't like the whites pace rule.does ruby has it? Ruby does not have significant indentation. However it does have a couple of instances where spaces between tokens matter (like `a[b]` meaning "access the `b`th element of the variable or nullary method `a`" while `a [b]` means call the method … | |
Re: If you read the comments on the accepted answer, you get the whole story: The only native code in .net .exe is a single jump instruction. This native code is ignored on *both* modern Windows systems and on Mono. It's only relevant for Windows systems that predate .net. None of … | |
Re: To answer the question in the title: There's no way to find out the number of elements in an array if you don't know its type, but it's also not possible not to know the type of an array unless you only have a (void or otherwise casted) pointer to … | |
Re: You should never prefer macros over inline functions. The only case where you'd use macros would be if you're writing for a compiler that does not support inline functions¹ or you're using macros as something other than a poor man's inline functions² - though even then you should think about … | |
Re: 3(1-x3) This is interpreted as "call the function `3` with the argument `1-x3`" and since `3` isn't a function, you get that error message. I assume you simply forgot a `*` there. | |
Re: You're returning `false` if the month is between 1 and 12 or the day is between 1 and 31 or the year 1753 or later. So if you want to get true, you have to give a day that's less than 1 or greater than 31 (and if it is … | |
Re: You can call a function that gets each piece, but your `getOperator` function needs to return `+`, not `'+`. For example this would work: (define (get-operator expression) (cond ((some condition) +) ((other condition) *) (...))) But this will not: (define (get-operator expression) (cond ((some condition) '+) ((other condition) '*) (...))) … | |
Re: The first is undefined behavior because there is no sequence point between function arguments. The second might be due to differences in precision when the value is only held in a register versus when it is stored in memory. That's my best guess anyway (though I don't think it's conforming … | |
Re: It's not quite clear to me, what you're trying to do here. If you want the division to only happen if `x = 1` is false, it should be inside the `else` block of the first `if`. Also every `if` needs an `else`, so your first `if` causes a syntax … | |
Re: > You are creating a pointer to an array No, he's not. He's creating an array of arrays of pointers. > and trying to output the size, this is not allowed sice the compiler does not know what the pointer is pointing to. Yes, it's allowed and yes, the compiler … | |
Re: You're defining your function as `f x y`, so it's a curried function of type `''a -> ''a list -> bool`. However you call it recursively as `f (x, tl y)`, so you call it with a tuple as its argument. If we insert a tuple `''b * ''b list` … | |
Re: Can you be more specific about what kinds of problems you're looking for in terms of scope and "topic" (like should they be more about algorithms or application design etc.) and how tough they should be? If you're interested in algorithmic problems, you can find ones of various difficulties on … | |
Re: Yes, it's undefined behavior. `<<` does not introduce a sequence point, so you are indeed modifying `a` twice without a sequence point in between. | |
Re: As the error message says, `input` only expects a single argument (or none), but you give it three. The `print` function can take multiple arguments and will then just print one after the other (on the same line). The `input` function does not do that - you have to call … | |
Re: Are you sure you don't get any errors on the lines where you call `push_back`? Because that's where I would expect errors to happen. Anyway the problem I see is that your functions are member functions of CAle and thus need to be called on an object of type CAle. … | |
Re: In Python a variable is defined when you first assign something to it. In your code you never assign anything to `y`, so it is not defined. You can not use variables that are not defined. As you already figured out, assigning something to `y` before the loop defines `y` … | |
Re: It's valid, but it very likely won't do what the OP wants it to. You'll need parentheses around the arguments and the whole expression (though the latter doesn't matter in this case). Or they could make their life 1000 times easier and define it as a function instead of a … | |
Re: Currently you have a regex that matches the whole string and then replace that with 'a'. So the whole string is going to be replaced with a single 'a'. If all you want is to replace every character with one 'a' per character, just use a regex that matches a … | |
Re: Here's my solution in Brainf#ck: https://gist.github.com/anonymous/6422016 Sample run: Please enter your favorite food: apple Please enter your second favorite food: banana This will be your new favorite food: applebanana This was fun. Edit: Moved the code to a gist because I realized it's way too long to post here. | |
Re: The return value of `execfile` is always `None`. All it does is to execute the code in the file. It does not check whether the last statement in the file is an expression and if so return its value or anything like that. If you want to use `func`'s return … | |
Re: The construct `template<typename T>` is used to paramatrize classes, structs, unions, functions or, in C++ 11, type aliases with type parameters (or in some cases other compile-time parameters). So `template<typename T>` must be in front of the definitions of one of those things (like `template<typename T> class Foo {...}`). In … | |
Re: > I'm guessing you're using Python 3.x where print() takes exactly one argument. That's not true. In Python 3 `print` takes arbitrarily many arguments. Further the OP's code won't work in Python 2 either. The syntax to call `print` (or any other function) with multiple arguments in Python 3 is … | |
Re: The `stringstream` class has no copy assignment operator (and no copy constructor, but that's less relevant). Thus you can't write things like `entries[key] = SS;` or `SS = i->second;`. You can make your code work by directly working with the objects in the map and avoiding any copies. | |
Re: `qsort` calls the compare function with pointers to the values as arguments. Since `qsort` can work with any type of array, those pointers are void pointers. So a comparison function given to `qsort` must take two (const) void pointers as arguments. So that's why the signature of `compare` looks like … | |
Re: If a function is nested in another function, you're not allowed to use unqualified `exec` in either of the two functions. Unqualified in this case means "without `in`". An explanation of why this limitation exists can be found [here](http://stackoverflow.com/a/4488826/149392). In your code you don't really need `exec`. To set and … | |
Re: Have you tried to compile the code? That should give you a list of errors telling you some of the things wrong with that code. | |
Re: > Perhaps this one That was supposed to linked [here](http://en.wikipedia.org/wiki/Brainf*ck), right? | |
Re: Your struct members are arrays of pointers, but you're treating them as if they were just pointers. Note that you can't assign to arrays and even if you could the values that you're trying to assign them are plain pointers, not arrays of pointers. | |
Re: > Now i wanted it to sort using bubblesort and structures. Why? Unless you have a very goood reason not to, you should really use `std::sort`. And even if you do have a very good reason, I don't see why you'd want to use bubble sort instead. I also don't … | |
Re: OP doesn't have an array of strings where he wants to check each element string. He has one string of which he wants to check every substring. Iterating over all possible substrings and calling is_palindrome on each of them (which is basically what the OP is doing now - albeit … | |
Re: When people talk about stdout being line-buffered, that means that if you do `printf("Hello ");`, then wait for some seconds and then `printf("world!\n");`, the output will appear all at once as "Hello world!" when the couple of seconds are over. If you used stderr instead (or you flushed stdout after … | |
Re: That line makes no sense, that's why you don't understand it. As you said, it's casting to `int*` and then back to `char*`. It could just as well be written `p = p;` (or just left out altogether because obviously that's a noop). Line 7 should be `p = (char*) … | |
Re: Which parts are you confused about specifically? The `%c`s in the format string are used, so that the `"` characters (ASCII value 34) can be inserted without messing with backslashes. Other than that the main trick is that `str` is used both as the format string as well as the … | |
Re: > arr itself does not have a memory address. I wouldn't say it that way (you yourself refer to `arr`'s address a couple of times in your post). Its address just happens to be the same as that of its first element. > So the result would be the address … | |
Re: When you call a function, you need a pair of parentheses. Thus it should `next.read_name()`, not `next.read_name`. Also your `read_name` is infinitely recursive and can't possibly work. And all it does (other than overflowing the stack) is to write to a local variable that it then never uses - that … | |
Re: `"GOOD EVENING"` is an array of characters. If you take any array or pointer and write `p + i`, you get a pointer pointing to the address that's `i` elements after the location that `p` points to. So in case of an array, `arr + i` (or `i + arr` … | |
Re: The declaration of `get_name` says that the return type is `string`. The definition says that the return type is `void`. | |
Re: > but if i want to know without running it ? Then you run it in your head. First note that the return values of the first three `fork`s do not matter - you assign each of them to `ret`, but then you overwrite them right afterwards without using them. … | |
Re: ~s.o.s~, I think you overlooked the fact that `someboundmethod` is never actually called in the james' code. `d` simply stores a reference to the method `someboundmethod` of the object returned by `foo()`. Since that method is bound to the object, the object will live at least as a long as … | |
Re: > string a string within a string Pardon? int potion = 30; int hiPotion = 70; int ether = 20; item[numItems++] = potion; item[numItems++] = hiPotion; item[numItems++] = ether; I'm not exactly sure what you intend those lines to do, but I guarentee you that they won't do that. `string[index]` … | |
Re: Generally you shouldn't use assignment to initialize your members inside the constructor. As you noticed, it doesn't work. It also calls the default constructor, followed by the assignment operator, which might be needlessly expensive for some classes. Also it won't work if the default constructor or the assignment operator aren't … |
The End.