166 Posted Topics
Re: Can you provide us with the code you have for the `registers()` function? Perhaps the reason you're getting an extra percent sign is because your function is tacking it on automatically. If it's not, I would have a reason to believe there's something wrong with your compiler because when I … | |
Re: `argv` is not a `char`, it's a pointer to a pointer to a `char`, so the comparison `argv != '\0'` makes no sense. You really shouldn't be modifying `argv` directly by incrementing it anyway. | |
Re: The physics engine is actually the easiest thing you can possibly do when designing a 2D game like you describe, especially if the framework of the game engine is written in such a way that time is cut up into "ticks" and the physics updates on each of these ticks … | |
Re: You forgot to post Personnage.h so we might not be able to help you troubleshoot your problem. Can you at least tell us *which* variables it's complaining about being undefined? | |
Re: > Where am I going wrong? If you had given your variables descriptive names so you could easily read through what your code is doing, or at least provided comments illuding to your train of thought when writing this program, you likely wouldn't have to ask us this question. | |
Re: On line 43, `while(stillguessing == true);` you have actually results in an infinite loop if `stillguessing` is true, because of the semicolon. Remove the semicolon to fix it. | |
Re: In the case that you've presented here, `sizeof(a)` is resolved during compile. The only time it's resolved during runtime is when you're dealing with C99's variable length arrays. The reason the above code works is that the number of bytes taken up by an `int` is always going to be … | |
Re: > That was a valid program, if written 30 years ago. If by "valid", you mean "it compiles". The `void main()` means it's techincally not legal C++. > You must use either std::cout or issue the following statement before using cout: using namespace std; I personally use like to include … | |
Re: You'll have to write code manually that will sort the array. You can use Google to find various sorting algorithms you can use. | |
Re: > thats why i am using memset which fails. This isn't what `memset()` is supposed to be used for. It does byte-by-byte setting to a specific value. You're going to have to use the loop. | |
Re: More than likely, your program will terminate immediately. Sometimes it will keep going, overwriting memory that you're not supposed to will almost certainly cause your program to malfunction somewhere later. My advice is that you're not supposed to do it. | |
Re: In the future, if you have a new question you should create a new thread. Otherwise, people will skip over your thread thinking it's solved. The crash is located on the line where you call `fclose(fpOUT)`. Upon further inspection, it appears that you never actually open `fpOUT` so why it's … | |
Re: There is no difference, functionality-wise between `char** argv` and `char* argv[]`. It's all a matter of preference. | |
Re: Uniform initialization refers to this, correct? class xypoint { public: float x; float y; xypoint(float xx, float yy) : x{xx}, y{yy} { } }; xypoint returnpoint(void) { //Equivalent to "return xypoint(3, 4);" return {3, 4}; } I don't see what's so controversial about it. To me, it just looks like … | |
Re: Clarifying what Adak said, here's what you should know: The & symbol (address-of operator) will return the address of a variable (where it is stored in memory). If you have declared an integer called `foo`, then `&foo` would be its address. When you're dealing with`printf()`, you only really need to … | |
Re: When you're using range-based for loops, the variable you declare to the left of the colon must be at type that refers to an element of the array or list on the left. Take the following code: #include <iostream> using std::cout; using std::endl; int main() { int array[4]; for(int& element … | |
Re: We would have to get a copy of what file you're working with to even begin to understand what your problem is. | |
Re: I reccommend nullptr's suggestion. You're going to have to get used to the double percent sign anyway, because there are some situations where you need to have both a format specifier *and* a percent sign in the same call to `printf()`. printf("Jimmy got a %d%% on his quiz!", percentage); | |
Re: You're trying to grab the lowest five values in your array, right? What would really help you is if you commented your code, so you're forced to explain your thought process to yourself. That way, it will become more obvious why your code doesn't work. The reason your program is … | |
Re: > Not possible. Line 27 is wrong, as I explained in my last post. open() doesn't take a std::string as the first argument, it takes only char*. Perhaps he's using some old or otherwise nonstandard compiler that's somehow automatically typecasting `std::string` to `const char*`? | |
Re: What you're probably looking for this the pre/post build steps tab under your project's `Build Options...` menu, which will allow you to set certain scripts to be executed whenever you build your project. Go to `Project` > `Build Options...` and then go to the tab that says `Pre/Post build steps`. | |
Re: When you're using macros like this, please pay attention to exactly what the code looks like when your macro is expanded. The code you have here is equivalent to writing the following: #include <stdio.h> #include <conio.h> void main() { int i=5; int j=for(typeof(i) i=2; i<=n; i++){f *= i}; printf("%d",j); getch(); … | |
Re: The only thing you'll need to do here is to reset `total` to zero at the beginning of your loop. That action alone will fix your code. > You're missing a few brackets and others aren't correctly placed. There are no missing brackets here, and the brackets aren't placed incorrectly … | |
Re: That code uses old, nonstandard functions like `kbhit()` and `gotoxy()`, which are functions that you'll hardly ever see outside of ancient compilers like Turbo C++ for DOS. Your best bet for ever getting this to work is trying to find curses.h on Google, and I'm not even sure if that … | |
Re: Unfortunately, it would have to be even more complicated that that. You have to be able to intelligently ignore `//` when it occurs in quotes, otherwise, you would end up cutting strings apart. Take the following code, for example: #include <stdio.h> int main(void) { printf("I like to // eat apples.\n"); … | |
Re: Have you written any code at all? Show us what you have working. | |
Re: Here's how I comment your code. Please note that, according to your code, 2 is not a prime number. You might want to fix that. import java.util.Scanner; //This line helps the compiler find the class file Scanner. public class PrimeNumber{ //Defines a class called PrimeNumber public static void main(String args[]){ … | |
Re: I know what the OP is talking about, I have dealt with some pretty nasty code in my time. I think weird problems like always-true loop conditions that only execute once, etc. are rare problems though and they're much easier to fix. I once took a venture into the Doom … | |
Re: We're not going to go through your entire program, line by line, and figure out what's wrong with it. Unless you tell us what problem you're having and where, there's no point in 'debugging' it. | |
Re: Sevaral problems here: **1)** You're using `charChoice` as an index for accessing your `charArray[]` array. The character `'c'` is equal to 99, so you're always just overwriting the last element of your array. **2)** You successfully save the character that the user types into `charArray[charChoice]`, but then your `for` loops … | |
Re: The reason your program is behaving so unpredictably is because you are not initializing the variable `res` in your `seno()` function, nor are you initializing `sin1` in your `sen()` function. Because you are using the values of these variables before initializing them, you are invoking undefined behavior. I could go … | |
Re: The reason it's skipping is becuase `char` is actually a *signed* type, which means that it includes positive and negative numbers. This means that, when trying to interperet a `char` as an 8-bit integer, its effective value range is actually -128 to 127 instead of 0 to 255. When a … | |
Re: When you have two functions of the same name that take a different list of parameters, this is called overloading a function. When you do this sort of thing on a class constructor function, it is callled an overloaded constructor. Your default constructor is the class constructor that you define … | |
Re: Because the different format specifiers tell `printf()` to interperet the value differently when displaying it. When you use `%c`, it tells the program to read `ch` as a single character, in this case printing out the character with the ASCII value of 23. When you use `%d`, it tells the … | |
Re: If you're wondering why nullptr made these suggestions, here's why. On line 14, you're calling `getch()` but you're not actually *storing* the value returned by it anywhere, so the program isn't doing anything with your input. Changing the line to `again = getch();` fixes this problem. The reason he's suggesting … | |
Re: What code do you have so far? You're supposed to give us what you have so far, and we'll be happy to help but, but we're not allowed to be doing your homework for you. | |
Re: A segmentation fault indicates that you've accessed memory you shouldn't have. You should check variables that are being used as array indexes for these sorts of problems. This is one of those cases where you should debug with `printf()` to find out where your problem is. Track the value of … | |
Re: Until we see what the `CALL_DATA` struct or class looks like, we can't really know for sure. | |
Re: You're already halfway there when it comes to understanding this line, then. For this code to make sense, `src` has to be a pointer to a pointer type, such as `char**`, and `offset` has to be a pointer type, such as `char*`. What this particular line of code is doing … | |
Re: You're not accessing an array wrong, you're causing a stack overflow because `Solve()` keeps calling itself over and over again when the parameter is zero | |
Re: Assuming you're giving us all the information we need, there's a ton of ways to do this without using loops and `cout`. One could use standard C functions like `puts()` or `printf()`, for example. #include <cstdio> int main() { printf("**********"); return 0; } | |
Re: Your equality comparisons makes so sense in `circleIntersections()`. On line 40, your condition is `else if(quadraticRoots(h,k,r,x1,x2)<0)`. Why are you checking to see if the number of roots is less than zero? Because `quadraticRoots()` only ever returns values of 0, 1, and 2, this `if` statement is never true. You probably … | |
Re: When you push a `char*` into a vector, you're not adding the actual characters to the vector, but rather a memory address that points to the characters. What's probably happening in your case is that `file.cFileName` (a memory address) remains the same, so you keep pushing the same value over … | |
Re: `malloc()` is C's equivalent of C++'s `new` operator. It is usually defined in `stdlib.h`. It allocates memory for your program to use. It takes a size argument, which must be manually scaled depending on the size of whatever type of data you're trying to allocate. For example, to allocate 6 … | |
Re: Your problem is in line 11. void insert(int i, string elem, vector<string> st) What you're doing here is a pass-by-value operation. This means that you're not actually passing your vector to the function, but rather just a *copy* of that vector. Your function modifies the copy, but the original vector … | |
Re: Attempting a compile got me some errors. On line 138, you have `printPayroll( recordlist[] );`. There is no need for these empty brackets unless you're declaring an array. Remove them and that error should be solved. On line 164, I get the error that `r` has not been declared in … | |
Re: What are you trying to do with the variables `int u` and `int c`? It looks like you're trying to count the number of elements with both with `u`, but every time you increment it, you also make `c` the same value. In your `for` loop, you're setting `c` to … | |
Re: Let's go through this problem by problem. **1)** You got completely confused while naming your member variables. As pyTony said above, in `student.h`: int newid; string newname; Should be changed to: int ID; string Name; To finish fixing these naming conflicts, change `Student::Student(int ID, string Name)` to `Student::Student(int newid, string … | |
Re: It's to make sure that the user of the class doesn't touch member data that he's not supposed to, or that when he does, it's in a fashion that is defined by the class (via a getter or setter function). In my opinion, a "read only" keyword would have been … | |
Re: > and you can use void main() there is no need of making it int. Disregard this advice, Hitman. > then what is the problem??? This should explain why `void main()` is not only wrong, but it can also be dangerous: http://users.aber.ac.uk/auj/voidmain.cgi Otherwise, the above code is more or less … |
The End.