389 Posted Topics

Member Avatar for eric_arambula

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 …

Member Avatar for eric_arambula
0
1K
Member Avatar for Jalaishaa

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 …

Member Avatar for Jalaishaa
0
182
Member Avatar for drsnet41

`<` 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 …

Member Avatar for sepp2k
0
12K
Member Avatar for ddanbe

`{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 …

Member Avatar for Triryche
2
580
Member Avatar for Andy90

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

Member Avatar for Ancient Dragon
0
674
Member Avatar for Labdabeta

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 …

Member Avatar for rubberman
0
306
Member Avatar for cambalinho

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 …

Member Avatar for cambalinho
0
248
Member Avatar for exfoxs28

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

Member Avatar for exfoxs28
0
240
Member Avatar for Bhavya scripted

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

Member Avatar for Bhavya scripted
0
232
Member Avatar for MasterHacker110

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 …

Member Avatar for sepp2k
0
259
Member Avatar for cambalinho

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 …

Member Avatar for cambalinho
0
798
Member Avatar for nitin1

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 …

Member Avatar for sepp2k
0
178
Member Avatar for mical700

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.

Member Avatar for mical700
0
122
Member Avatar for mc3330418

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 …

Member Avatar for Ketsuekiame
0
125
Member Avatar for DarkLightning7

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) '*) (...))) …

Member Avatar for DarkLightning7
0
239
Member Avatar for prakash4

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 …

Member Avatar for sepp2k
0
287
Member Avatar for android_gl

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 …

Member Avatar for sepp2k
0
112
Member Avatar for usama sadaqat

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

Member Avatar for sepp2k
0
156
Member Avatar for DarkLightning7

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` …

Member Avatar for DarkLightning7
0
710
Member Avatar for killer88

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 …

Member Avatar for killer88
0
211
Member Avatar for nitin1

Yes, it's undefined behavior. `<<` does not introduce a sequence point, so you are indeed modifying `a` twice without a sequence point in between.

Member Avatar for vijayan121
-1
219
Member Avatar for zswinford

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 …

Member Avatar for sepp2k
0
14K
Member Avatar for Elixir42

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. …

Member Avatar for Elixir42
0
279
Member Avatar for farmwife

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` …

Member Avatar for james.lu.75491856
-1
178
Member Avatar for general2012

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 …

Member Avatar for general2012
0
230
Member Avatar for Taruna_1

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 …

Member Avatar for vegaseat
0
323
Member Avatar for marethamogale

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.

Member Avatar for sepp2k
0
133
Member Avatar for farmwife

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 …

Member Avatar for farmwife
0
1K
Member Avatar for christinetom

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 …

Member Avatar for Kenney_1
0
3K
Member Avatar for martin.schmidt.9465

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

Member Avatar for martin.schmidt.9465
0
20K
Member Avatar for dospy

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.

Member Avatar for sepp2k
0
392
Member Avatar for sireiz

`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 …

Member Avatar for sepp2k
0
2K
Member Avatar for james.lu.75491856

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 …

Member Avatar for sepp2k
0
349
Member Avatar for themenucha

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.

Member Avatar for RickRoss$$
0
252
Member Avatar for CCHIndiaStore

> Perhaps this one That was supposed to linked [here](http://en.wikipedia.org/wiki/Brainf*ck), right?

Member Avatar for mike_2000_17
-3
370
Member Avatar for hassje

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.

Member Avatar for rustysynate
0
163
Member Avatar for every1play

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

Member Avatar for rubberman
0
316
Member Avatar for nirbilcahn

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 …

Member Avatar for vijayan121
0
412
Member Avatar for lewashby
Member Avatar for somjit{}

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 …

Member Avatar for rubberman
0
2K
Member Avatar for ram619

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*) …

Member Avatar for Razahcy
0
220
Member Avatar for ram619

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 …

Member Avatar for sepp2k
0
361
Member Avatar for dev90

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

Member Avatar for sepp2k
0
155
Member Avatar for charles.dupree.37

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 …

Member Avatar for rubberman
0
3K
Member Avatar for dev90

`"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` …

Member Avatar for dev90
0
128
Member Avatar for charles.dupree.37

The declaration of `get_name` says that the return type is `string`. The definition says that the return type is `void`.

Member Avatar for charles.dupree.37
0
7K
Member Avatar for nitin1

> 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. …

Member Avatar for lalitha2294
0
279
Member Avatar for james.lu.75491856

~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 …

Member Avatar for ~s.o.s~
0
185
Member Avatar for Lp_baez

> 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]` …

Member Avatar for Lp_baez
0
476
Member Avatar for Labdabeta

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 …

Member Avatar for mike_2000_17
0
410

The End.