- Strength to Increase Rep
- +6
- Strength to Decrease Rep
- -1
- Upvotes Received
- 48
- Posts with Upvotes
- 44
- Upvoting Members
- 34
- Downvotes Received
- 1
- Posts with Downvotes
- 1
- Downvoting Members
- 1
- PC Specs
- Dell Inspiron 1525, Ubuntu GNOME 13.10
166 Posted Topics
Re: > Does anyone know if ubuntu is good for programming? It depends on what you're programming. For the most part, programming something in Linux is simpler than programming it in Windows, just because libraries are handled by a package manager rather than having to go through the tedious process of … | |
Re: [quote]I really do like programming, it's just that the problem solving part is difficult for me.[/quote]I have devastating news for you. [quote]I forgot to mention that I'm relatively new to C++, and I have no idea what most of that means :p[/quote]Don't fret. I've been using C++ for five years … | |
Re: > Should I get ubuntu on my mac? Is there a particular task that you want to accomplish on Ubuntu that you can't do on your current OS? It may not be worth the effort if you can do everything perfectly fine on your Mac as it is. > when … | |
Re: Because you're essentially looking at the least significant bit first, you're printing them first, and as a result, the number is being printed backwards. A couple of notes here. The line `rem = rem%10` more than likely does not do anything because the line `rem=quotient%2` guarantees that `rem` will either … | |
Re: First code: You're calling `mainPage()` as if it belongs to the global scope. The way you've written your code, though, it actually belongs to your class `foo`. My best bet is, because of the context, it assumes you're declaring an implicitly-`int` function called `mainPage()` inside of both `minus()` and `add()`, … | |
Re: Ancient Dragon: Are you sure you're compiling as C and not C++? There are no VLAs in C++. | |
Re: You're erasing elements by position rather than by value. Once you start erasing values like that, you can't expect `v[number]` to be equal to `number` anymore. A better solution to this problem would be to have an array of `bool` keep track of which numbers can be prime, and which … | |
Re: You would make the fuction virtual, which allows you to override the behavior of a function when defining the child class. It should be as simple as changing `void set_dimensions()` as `virtual void set_dimensions()` in your `shape2D` class, and then rewriting `shape3D::set_dimensions()` to accept all three dimensions. There may also … | |
Re: I would recommend [icode]enum[/icode] in this case because that's exactly what they're there for. | |
Re: When you pipe two programs together via the shell, it actually just pumps the `stdout` of the program on the left into the `stdin` of the program on the right. There is no real need for calling `pipe()` inside your program in this case. For example, if I wrote the … | |
Re: main.c:7:6: error: 'i' undeclared (first use in this function) main.c:7:13: error: 'y' undeclared (first use in this function) main.c:9:3: error: 'x' undeclared (first use in this function) main.c:11:2: error: 't' undeclared (first use in this function) ![]() | |
Re: Is there any particular reason you're using `for_each` when you already have C++11's range based `for` loops available? Is it part of an assignment that your `add()` function has to exist? The following would be easier. for(auto& i : vec) i += 2; for(auto i : vec) cout << i; | |
Re: Another way to print the values pointed to by the vector is to use C++11's new range-based `for` loops (if you have an up-to-date compiler). This way, you don't even have to declare your own iterator. for(auto ptr : ptrList) cout << *ptr << endl; | |
Re: > Is this memory efficient to split things up for developer "ease-of-use"? Even if it wasn't, it doesn't matter. Code maintainability and readability is a lot more important than shaving off a few bytes here and there. Your time as a developer is a worth more money than a few … | |
Re: > That's quite a bit of difference, especially if there are thousands of nodes in the linked list. But don't compilers typically like to pad structs so that they are aligned a certain way (Like making the size a multiple of four)? Assuming an environment where `sizeof(int) == 4` and … | |
Re: What exactly is Vvariant supposed to be? It's impossible to get the value of a `void*` (without typecasting it first), and it's dangerous to dereference a pointer that is `NULL`. | |
Re: You would be right. Arrays decay into pointers when you use them in a name context. | |
Re: He means this sounds like a homework assignment, and we don't do those for people. You actually have to show some sort of an effort towards solving the problem. | |
Re: Because you're recursively calling `printtree()`, this means you're also calling `fopen()` over and over again. As a result, you're overwriting the file every time you print something to it. (The file handle is also not getting closed properly. I would suggest opening the file outside of `printtree()`, and modifying the … | |
Re: You're using `strlen()` incorrectly. It doesn't take an `int`, it takes a `const char*`. The way you have your code written, it might be easier to simply count, one by one, how many characters there are by counting them as you print them, using `textLength` as a counter. if(file) { … | |
Re: You're spoonfeeding the answer to what is clearly a homework assignment to somebody who doesn't want to do any of the programming themselves. This is the reason so many people can get CS degrees without even knowing how to do FizzBuzz. I hope his professor is at least smart enough … | |
Re: NathanOliver: There is actually a `getline()` for `std::string` as well. `istream& getline (istream& is, string& str);` | |
Re: Are you doing this in an initialization context? Because if you do something like the following declaration: int *ptr = 12; It probably will not error, but instead make `ptr` point to the (probably invalid) memory location of 12. Otherwise, I'm absolutely baffled that no error occured. | |
Re: jwenting: In India, schools have unfortunately standardized around Turbo C/C++. | |
Re: As a general rule of thumb, if your program can be "optimized" by changing one little operator like that, then the compiler will likely do it for you. That being said, the short-circuiting behavior mentioned by deceptikon is important to note. Using the `&&` operator ensures that unnecessary checks are … | |
Re: Your usage of one-letter variable names, which are all declared at the very top of your `main()` function, has your program nearly impossible to read, let alone debug. You need to provide descriptive variable names if you want your stuff to be self explanatory. Do you seriously think it's good … | |
Re: > PS: I see that a lot of people are already familiar with C++11 to the point that they don't think about it when they use its features. Is it now considered 'best practice' to use the new features? I am mainly concerned due to the lack of universal support … | |
Re: > At lines 33 and 38 your formal parameters are floats but you call the function using doubles - you can fix this by changing floats to doubles ( ex: 5.5 to 5.5f ) or simply change the parameter's type from the methods's header. Doubles are automatically converted to floats … | |
Re: You've got the right idea, but overloading really isn't polymorphism at all. | |
Re: > The while statement is a loop that contininues to execute until some condition is met. I think you meant to say a while statement is a loop that continues to execute *while* some condition is met. | |
Re: The problem is on this line: `LH = 0x0120DE13 + 1;` This should instead be: `LH = 0x0120DE13 + i;` | |
Re: I personally use CMake myself for all of my projects. It's a really simple build system and it avoids all the boilerplate that you have to go through when writing a Makefile manually. If you're a FOSS purist, though, keep in mind that although CMake is open source software, it's … | |
Re: What you would do is 1) Prompt them for the row number via `cin` (in the range of 1-3 if you're going for easy human interface, or 0-2 if you're lazy :P ) 2) Validate the input to make sure it's within the acceptable range, and repeat step 1 if … | |
Re: > In the main, I try to print the the elements of sArray1 using sArray. It doesn't work. I don't see you trying to print anything anywhere. | |
Re: > One is, is sizeof(char *) supposed to be size 8? It should be, provided you're writing a 64-bit application. > And also, when I look at the elements of list, list[0] is empty, list[1] and list[2] have something in it, and list[3] is invalid. We would have to actually … | |
Re: Out of all of the IDEs I've tried, I prefer Code::Blocks the most because it's the most minimalist of the modern IDEs while still giving me the features I need in order to develop larger projects (being able to quickly find the delcaration of a variable or definition of a … | |
Re: It depends on the operating system you're using. In Windows, the _mkdir() command does what you need. For Unix, see http://linux.die.net/man/2/mkdir . | |
Re: You can't just make your thunderball animation a `while` loop. When you have that loop going, no other code outside of that loop will execute, and this is likely the reason your character freezes on screen every time you shoot a bullet. If you want these things to happen simultaneously, … | |
Re: > Years ago I picked up the habit, I don't know where from, of always using > `#define NUL char(0)` > for 0 terminators in ASCII strings, and NULL for pointers. I wouldn't recommend that at all, and to be honest I don't see the point of using macros for … | |
Re: For some reason, I am able to run the first program without any issues whatsoever, which absolutely baffles me because looking at it, it probably *should* crash. You create a pointer called `pr1` which is *supposed to* point to a `linkedlistchain`, but you never initialize it nor set it to … | |
Re: > std namespace is defined inside the header Nope, that's not how it works. The `std` namespace isn't "defined" anywhere. All the `namespace std {...}` stuff is saying is that the stuff contained in the brackets *belongs* to the `std` namespace. > "deceptikon" I thought that header files are reside … | |
Re: > Are struct names supposed to be defined somewhere else? Yes. When you declare a variable that is an instance of `usb_device_id`, you must first tell the compiler somewhere else what a `usb_device_id` *is*. If you have already written a declaration of this struct, we might have to see it … | |
Re: You're accessing your arrays incorrectly. When you have an array declared as `int num[2]`, `num[0]` is your first element and `num[1]` is your second element. You're passing values of `&num[1]` and `&num[2]` to the `scanf()` function. As a result, when you think you're entering your first number, you're actually entering … | |
Re: The problem is that by declaring a function in `Derived` that is the same name as the virtual function you declared in `Base`, you are actually *hiding* the original function that you declared in `Base`. These are little-known rules but they are rules nevertheless. When you have a function that … | |
Re: C-style strings don't work like that. A variable of type `char*` is a pointer, and as such it actually has to point to a valid memory location before you can modify information in it. I advise against using `char*` with `cin` anyway because there isn't a guarantee that what you … | |
Re: When used correctly, polymorphism is easily the most useful feature in all of C++. It's more particularly useful when you start getting into game design, where you often have large linked lists of actors, all belonging to different subclasses but all needing to behave differently from one another. In such … | |
Re: Although logically there should be a guarantee here that your function will reach a return statement, the java compiler doesn't seem to see it that way. I think there are two possible solutions: 1) Add an extra return statement that just returns some arbitrary value to appease the compiler. 2) … | |
Re: Usually, people just put the `main()` function in main.cpp (and sometimes a function or two that will only ever be used by `main()`), and leave other functions in other files. The place where you actually "flesh out" the function, as you put it, is called the "implementation" of the function … | |
Re: The syntax in this program you've written is completely wrong. It doesn't even appear to be real C code. What do you think the lines `letter [a-zA-Z]` and `digit[0-9]` do? What's with the two percent signs on the next line? | |
Re: A function that prints something and then returns an integer is a bad example to try and understand the difference between a `void` function and a function that returns a value. Let's see if this clears things up, and please read the comments to understand what's going on here: #include … |
The End.