436 Posted Topics
Re: What's wrong with what you have? I mean, you're not going to find anything a lot shorter. | |
Re: The only thing that comes to mind is in your malloc call the value is an unsigned long long, but malloc takes a value of type size_t. size_t is probably going to be unsigned long or unsigned int instead of unsigned long long, so your unsigned long long value gets … | |
Re: It's harder than it seems at first. 1-9 is easy, but 10-19 are different and need special cases. Then you need to do 20-99 and can reuse 1-9 inside, then 100-999 reusing everything with a prefix of n hundred. The higher the numbers you allow, the harder it gets to … | |
Some of the ads have the wrong z-index. The Verizon Wireless one is an example because it always stays on top of the forum and control panel dropdown menus. I can't get to some of the links that way and have to reload the page to get a different ad. … | |
Re: You don't always have to store the actual value the way float and double do. If the problem allows it, you can write your own data type that uses exponent representation just like you showed in your post: [code=c] typedef struct { long base; long exponent; } exponent_t; [/code] Then … | |
Re: [QUOTE]He claimed you can just do n++ instead of n = n->next. I disagree.[/QUOTE] With your List class that's true. But C++ allows you to overload operators to do different things. You can overload the ++ operator to do n = n->next. That's what the list<T>::iterator does: [code=c++] #include <iostream> … | |
Re: There is not a loop anywhere in that function. It should loop over the nodes until NULL and stop early if a match is found: [code=c] int found = 0; while (move != NULL) { if (move->level == level && move->id == id) { found = 1; break; } move … | |
Re: [QUOTE]How often are pointers to functions used?[/QUOTE] As often as they're needed? [QUOTE]Should i implement them in my programs?[/QUOTE] Function pointers work great for callbacks and generalized behavior at runtime. If you're doing something where they can be used and they're the best choice, you should use them. What you … | |
Re: tux4life, I challenge you to write the same program with the same features and restrictions and show me how it's so much better than mirfan00's that he deserved all of that harassment. You're quick to mouth off, but can you back it up with your own perfection? [QUOTE]This program is … | |
Re: [QUOTE=valinux]I have found out that goto is bad in C++? Why? I just got a book the other day (for my birthday ) and it says it is fine to use.[/QUOTE] Happy birthday! :) goto is too easy to use the wrong way. I think K&R calls it "infinitely abusable". … | |
Re: If you specify a value, it overrides the rule. If you don't specify a value, it defaults to one more than the previous constant. If you don't specify any value for the first constant, it starts at 0: [code=c++] enum { A, // A == 0 B, // B == … | |
Re: If you switch to standard C++ instead of an older version, you can use the STL vector class and initialize it with an array. The Boost library has a way of doing it directly to a vector without the array, and C++0x will add that into the language itself. But … | |
Re: It helps to know what you expected. I'll guess that you wanted -25.0. Here's why you get -100.0. [ICODE]a=2*(s-u*t)/squ(t);[/ICODE] uses the squ macro, and squ replaces itself with the macro text [ICODE]x*x[/ICODE] with x replaced by the argument t. Your statement looks like this after the replacement: [code=c] a=2*(s-u*t)/t*t; [/code] … | |
Re: [QUOTE][CODE]main();[/CODE][/QUOTE] Calling main recursively isn't allowed in C++. It's a bad practice even if your compiler allows it. ;) [QUOTE]What were you trying to accomplish?[/QUOTE] I think it's an input parsing algorithm that looks for fixed point values or variations of PI. The fixed point value is checked and if … | |
Re: [QUOTE]Good luck and thanks![/QUOTE] I think it would be better to show your code with the pointer stuff so that someone can help you understand where you went wrong than to show your code without the pointer stuff and hope somebody does all of your work for you. | |
Re: Your numbers are all chars. cout will print them as chars, not ints. But you can't print them as ints because some of them have to be 'X', right? So use an array of strings instead of chars: [code=c++] #include <iostream> #include <string> #include <stdlib.h> #include <time.h> using namespace std; … | |
Re: Expecting that this thread will be moved to the C# forum, I can answer it as a C# question. [QUOTE]EncryptMyData (byte[] plainData, out byte[] encryptionKey)<-- what the mean of this???[/QUOTE] I'm guessing you mean the out parameter? It means that the caller passes in a reference of the same type … | |
Re: [URL="http://msdn.microsoft.com/en-us/library/ms686047(VS.85).aspx"]SetConsoleTextAttribute[/URL] can change the foreground and background: [code=c++] #include <iostream> #include <windows.h> using namespace std; HANDLE SetColor( HANDLE console, int fg = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE, int bg = 0) { if (console == NULL) console = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(console, fg | bg); return console; } int main() { HANDLE … | |
Re: [QUOTE]"cout" doesn't support any specific formatting.[/QUOTE] cout supports a lot of formatting options, and you can add more. It is a very flexible design, much more flexible than printf. But the design is very verbose and convoluted compared to printf. [QUOTE]You can use printf defined under stdio. Use a corresponding … | |
Re: [QUOTE][CODE]if (password == "pen15");[/CODE][/QUOTE] You have an extra semicolon at the end there. [edit] You also need to include <string> because you use the string class and getline. | |
Re: If you want to treat each row as an individual object, a 2D array is easier to work with and visualize. A good way to swap rows is a second array of pointers that point into the matrix. You swap those pointers for different sorting options and the matrix doesn't … | |
Re: I can't say what the problem is with what you've shown, but the list makes a copy of the object. Check your copy constructor for the Aircraft class. | |
Re: I think a better way to go about it is to change your code to do it the Linux way. You shouldn't be using system anyway because it is bad for security. Show which commands you're using from DOS and I can help you figure out how to do it … | |
Re: [QUOTE]What I had been using till now was "rusted, naff,useless" code.[/QUOTE] There's nothing wrong with writing code on an old compiler. You gotta do what you gotta do, and what you gotta do isn't ever ideal. ;) It's easy for some armchair critic to complain, but you're the one who … | |
Re: [QUOTE]Then it doesn't gather numbers correctly but stores the entire string[/QUOTE] That's what you tell it to do with [ICODE]getline(cin,problems)[/ICODE]. I can help you fix it by taking the entire line and parsing it, but I need you to describe the format of the problemset. Just showing your code isn't … | |
Re: [QUOTE=fadia;897958]what is the l for? and i didn't understand this>> while (l==1)[/QUOTE] It looks like another way to write a !done loop. These two are conceptually the same: [code=c++] int l = 1; while (l == 1) { if (/*not more to do*/) l = 0; else { //do stuff … | |
Re: It already prompts for enter again. I'm going to guess that the problem is with extra stuff being stuck in the stream when you prompt again. You should clear it out. A good way to do that is to use strings and getline so that there isn't ever any extra … | |
Re: [QUOTE=athlon32;896559]I'm have a small confusion, and i need a little clarification; when you make something on the heap, like this: [code=C++]int *somePointer = NULL; somePointer = new int;[/code] an int is created on the heap right? This would be the equivalent of doing something like...: [code=C++]int x;[/code] ...directly on the … | |
Re: You created a windows application project and don't have a WinMain function. WinMain is the entry point for windows applications. If you're writing a program that uses main instead of WinMain, change the project type to a console application. If you really do want a windows application, there has to … | |
Re: If the replacement lines aren't exactly the same length as the lines being replaced, you need to rewrite the whole file. If they are the same length you can just overwrite the first ten lines. | |
Re: I don't understand what the 0 and -5 thing is with that code, but your player's hit points don't ever get subtracted from. If you do [ICODE]player2-hit;[/ICODE], it doesn't change player2. You need to do [ICODE]player2=player2-hit;[/ICODE] to save the changes. Or [ICODE]player2-=hit[/ICODE] is a little shorter and does the same … | |
Re: A function pointer is still a pointer. If you set it to NULL or 0 it is a null pointer and then the test is easy: [code=c++] for (int x = 0; x < nFeats; ++x) { if (feats[x] != NULL) (*feats[x])(); } [/code] | |
Re: For a loose definition of 'word', you can use cin: [code=c++] string word; while (cin >> word) { cout << word << '\n'; } [/code] For a stronger definition of 'word', you should do more parsing than just looking for spaces. Punctuation and stuff like that wouldn't be a part … | |
Re: Use recursion: [code=c] #include <stdio.h> void PrintFileBackward(FILE *fp); int main() { FILE *fp = fopen("test.dat", "r"); PrintFileBackward(fp); return 0; } void PrintFileBackward(FILE *fp) { char s[20]; if (!fgets(s, 20, fp)) return; PrintFileBackward(fp); fputs(s, stdout); } [/code] Each time you call PrintFileBackward, the next line is read from the file. Then … | |
Re: [QUOTE=William Hemsworth;894044]One thing you could try:[code]long long num = 123456789123[COLOR="Red"][B]ll[/B][/COLOR];[/code]Just a guess though.[/QUOTE] ll looks too much like 11. LL is easier to see as a literal suffix. | |
Re: If you just want a reference, [B]"C: A Reference Manual"[/B] is the best. A good beginner book is [B]"C Primer Plus"[/B]. |
The End.