389 Posted Topics
Re: If you just write `int sum` or `int sub`, you'd be using those variables uninitialized in your loop, which would invoke undefined behavior. So don't do that. Your while loop will run until `value` is either equal to `'q'` or `'Q'`. This will only happen if the user enters 113 … | |
Re: > `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable) Do you have one of the runtimes listed at the URL installed? If not, that's your problem. You need to install one of them. If you do have one of them installed, it … | |
Re: No, it's perfectly fine to write `if(variable1 && variable2)`. What makes you think that doesn't work? | |
Re: Making a local variable `static` means that it will remember its value between multiple calls of the same function. It does not mean that other function can access that function. A variable that is defined within one function can't be accessed from other functions (at least not directly - it's … | |
Re: if (desired-options[i]>0.0) You never check whether `desired - options[i] == 0`. You should push the item on the vector and return 0 in that case. PS: Is there a specific reason that you're using `0.0` and not just `0`? I realize you want the code to work with all types … | |
Re: When defining template functions or member functions of template classes, you can't put the definitions in a separate file from the declaration. Both the declaration and the definition need to be visible to the code that uses your functions. So you need to put the contents of Dynqueue.cpp into Dynqueue.h … | |
Re: > Alternatively, you can add a request for input at the end of your program to force the process from terminating until input is provided. But he already did that: input("\n\nPress the enter key to exit.") | |
Re: Maybe the question says something about the array ending with a specific number? Like the last element of the array might be 0 or -1? In that case you can find out the size of the array by going through the array until you encounter that number. Or possibly it … | |
Re: u_char * newdata[raw_len] C++ does not allow variable length arrays, that is when declaring an array like this, the length must be a constant. So `raw_len` is not allowed as the length. There is no standard way to create arrays of unknown size on the stack. However some C++ compilers … | |
Re: The error message is saying that you specified the default value for `find_words` both in the declaration and the definition of the function. You're only supposed to do it in the declaration. | |
Re: The items sys.argv are strings. So if the user gives 949 as the argument, code will be the string `'949'`, not the number `949`. Since `==` does not automatically convert between different types, `949 == '949'` will be false -- only `'949' == '949'` would be true. So if you … | |
Re: Even if you could define methods within methods, why would you expect Fnction to become a static method of the Stuff class? The definition is not inside the Stuff class - not even indirectly. | |
Re: One way to do it would be to use `re.sub` with a function argument. That function could increase a counter every time it's called and then either return the given string unchanged or return the replacement string depending on whether the counter is equal to your n. | |
Re: > Your second example just catches one specific exception. It catches all exceptions that are a subclass of `Exception`. Since every exception is a subclass of `Exception`, that means it catches all exceptions -- just like the first one. | |
Re: You came across what error? If you're getting an error message, please post it. If your code acts differently than you want it to, please explain what you expect and in what way it acts differently. PS: Using `return` inside a for loop like you're doing, will likely not do … | |
Re: You defined your methods using the names Area and Perimeter with a capital A and P respectively. You tried to call them as area and perimeter with a lower case a and p. Since Python is case sensitive, that does not work. Also: If you want to call a function … | |
Re: Maybe it would be more fruitful to attempt to learn Python rather than hoping that someone will do your homework for you (spoiler alert: noone will). PS: Please don't post the same question on [multiple][1] [sites][2] on the internet at the same time. It's against the rules here and it's … | |
Re: You're invoking undefined behavior, the output could be anything (notably gcc will produce different output with -O1 than with -O2). It is highly unlikely that your compiler writes a specific byte sequence into bytes used for padding. Rather I'd expect it simply leaves them untouched, so they will just have … | |
Re: `%c` reads any character, including whitespace. So since you still have a space or newline in the buffer from the last scanf, it will just read that. If you use the format string " %c" with a space in front of the `%c`, it will discard all whitespace before it … | |
Re: It means "Text means a character array of size 80", yes. There's no such thing as an array of typedefs because typedefs are a compile-time concept only - they're not something that can be stored in arrays. The syntax of a `typedef` is basically the same as that of a … | |
Re: What do you mean by "oops"? I assume the oop part stands for Object Oriented Programming. What does the s stand for? Anyway object oriented programming in Ruby isn't fundamentally different than in other languages, though obviously the fact that Ruby is dynamically typed and otherwise also very dynamic makes … | |
Re: Each Animal object has an instance variable named `a`. Every time a new Animal object is created, its `e` variable is initialized to `new Animal()`, which creates a new Animal object. So every time you create a new Animal object, you create another Animal object. So if you create one … | |
Re: In Python (and many other languages) there is a difference between changing variables and changing objects. A statement of the form `myvar = new_value` will change the variable `myvar`. Most other things that you can do with `myvar` (like `myvar[i] = foo` or `myvar.append(bar)`) will change the object, not the … | |
Re: > Many string functions seem to work without the null byte... is it necessary to add it all the time? Which functions are you talking about specifically? If the function takes a size as an argument or only reads up to a certain delimiter in the string that's guaranteed to … | |
Re: It's always incorrect to use a pointer *that doesn't point to valid memory* to do anything at all. It's perfectly correct to take a pointer that points to valid memory containing a 0-terminated sequence of characters and pass that to a function that expects a string. | |
Re: The compiler doesn't recognize `Node` until after the typedef has been fully parsed. So you can't use the typedef inside the struct. In order to write a recursive struct, you'll need to name your struct without `typedef` and use that name in the struct. struct node { struct node* next; … | |
Re: The line `dice1, dice2, dice3 = numb(dice)` does not appear in the code you've posted, so I think you accidentally posted the wrong code. Assuming that the definition of `numb` that you gave in the code you've posted is the same one that you use in your real code and … | |
Re: If you're declaring a variable with `extern`, it must have external linkage. This means it can't be `static`. It is not possible to forward-declare a static variable. So your only option are to not make it static or to put the definition at the top of the file and get … | |
Re: What exactly were you trying to measure here? If you just wanted to measure the cost of lookups, wouldn't it have made more sense to just measure a function that makes a bunch of lookups in an already-built list or dictionary without measuring the time it takes to build the … | |
Re: Using which library? Or if that's part of the question: for which operating system? | |
Re: As the error indicates those names are not declared at the point where you use them. In C++, the declaration of any identifier generally must come before its use. So if you want to use InitScanner and ScanOneToken on lines 43 and 44, you need to declare them before then. … | |
Re: Why are you trying to boot from CD 5? I would expect that CD 1 is the boot CD and CD 5 is not. | |
Re: You should be getting a warning on line 19 telling you that you gave two pointers to scanf, but your format string only contains one specifier. If you didn't get that warning, you should increase the warnings level of your compiler. | |
Re: No, you can't do this - . and ' aren't overloadable operators. You can overload & for AND and ! for NOT though (and make OR | while you're at it). That way the operators are also consistent with those of the builtin bool type. PS: How exactly do you … | |
Re: Do you want to know how to concatenate a string and an integer using +? If so: by converting the integer to a string first. That might look like this: s = "foo" x = 42 foo42 = s + str(x) That said using `format` might be better than using … | |
Re: The + operator associates left to right, so when you write `"A+B= "+a+b` that's parsed as `("A+B= "+a)+b`. `"A+B= "+5` is `"A+B= 5"` and `"A+B= 5"+7` is `"A+B= 57"`, so that's the result. You need to add 5 to 7 first and then add the result to the string. To … | |
Re: In Python 2 the / operator returns an integer if both operands are integers - rounding the result down if necessary. So 3/2 would be 1 in Python 2. In Python 3 this behavior has been changed, so that / always returns a float even if both operands are integers. … | |
![]() | Re: You seem to think that if the end of file is reached, fscanf will store EOF in the given variable. It won't - it will simply keep the variable unchanged. The only way to tell whether fscanf successfully read a value is to check the return value of fscanf - … ![]() |
Re: > What happens when you add an element to a vector that is already at capacity? The capacity is increased (often doubled, but that's up to the implementation), new storage is allocated with the given capacity and the contents of the vector are copied to the new storage. > Does … | |
Re: Yes, you can use class files from different directories by adding all the directories to your classpath. If you're using an IDE, you can do so in your project's settings. If you're compiling from the command line, you can use the -classpath switch or the CLASSPATH environment variable to set … | |
Re: Variables that are declared inside a method will always go out of scope at the end of that method. You don't need to do anything special to make it that way. | |
Re: The distinction between O, Theta and Omega isn't about best- versus worst-case. You can use any of these notations to analyze any case you want. That is, the statements "QuickSort's worst case is in Theta(n^2)" and "QuickSort's best case is in Theta(n log n)" are both valid usages of Theta. … | |
Re: Here's one example of a class variable being used at the top level of the class definition: class MyClass @@number_of_instances = 0 def self.number_of_instances @@number_of_instances end def initialize @@number_of_instances += 1 end end As you can see, the class variable `@@number_of_instances` is used in 3 places here: it is read … | |
Re: Scheme already has a function named `append`, which takes multiple lists as arguments and returns the concatenation of all the lists. So you should name your function something else, like `append-element` perhaps. You can define your function by simply using the existing `append` function to concatenate the list you want … | |
Re: The reason that your numbers look the same when you print them is that by default printf rounds the number to 6 decimal places. If you use something like `%.20f`, you'll see that your two numbers really look something like this: float=3.09999990463256835938 double=3.10000000000000008882 So you see that the two numbers … | |
Re: You can not change the superclass of a class after it has been defined. That's just not possible. If you just asked out of curiosity, that's basically all there is to say. However if you asked because you have a specific problem that you think could be solved by changing … | |
| |
Re: > Bowls made by the Mayans and by the Sumerians still work today (if found intact). [..] are they better than the bowls actually made today? They're certainly a lot more expensive, so I can only assume they must be better. | |
Re: The first two lines don't load anything. You'd need a load instruction for that. They simply perform pointer arithmetic. The first line makes `$t0` point to the fifth *byte* of the A array. If A is an array of 32-bit values, that means that `$t0` points to the second element … |
The End.