436 Posted Topics

Member Avatar for yun

What's wrong with what you have? I mean, you're not going to find anything a lot shorter.

Member Avatar for csurfer
0
285
Member Avatar for kostasxx

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 …

Member Avatar for Tom Gunn
0
122
Member Avatar for tag5

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 …

Member Avatar for u8sand
0
313
Member Avatar for Tom Gunn

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

Member Avatar for Dani
0
173
Member Avatar for ganesh_bala

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 …

Member Avatar for Hiroshe
0
142
Member Avatar for cbaechle

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

Member Avatar for csurfer
1
1K
Member Avatar for sam511

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 …

Member Avatar for sam511
0
62
Member Avatar for athlon32

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

Member Avatar for athlon32
0
122
Member Avatar for mirfan00

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 …

Member Avatar for tux4life
-1
256
Member Avatar for valinux

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

Member Avatar for Tom Gunn
0
186
Member Avatar for Zay

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

Member Avatar for Zay
0
125
Member Avatar for Nikhar

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 …

Member Avatar for Nikhar
0
104
Member Avatar for ravikiran032

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

Member Avatar for MosaicFuneral
-1
102
Member Avatar for RoninMastaFX

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

Member Avatar for jephthah
0
135
Member Avatar for Hiroshe

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

Member Avatar for tux4life
0
154
Member Avatar for kangarooblood

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

Member Avatar for wildgoose
0
2K
Member Avatar for linsz

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 …

Member Avatar for linsz
0
113
Member Avatar for kangarooblood

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

Member Avatar for Tom Gunn
0
113
Member Avatar for Nikhar

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

Member Avatar for s_sridhar
0
109
Member Avatar for XxGunMastaxX

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

Member Avatar for WaltP
0
152
Member Avatar for niruyadla

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 …

Member Avatar for William Hemsworth
0
168
Member Avatar for eliza2044

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.

Member Avatar for tux4life
0
150
Member Avatar for NervousWreck

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 …

Member Avatar for NervousWreck
0
132
Member Avatar for Nikhar

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

Member Avatar for siddhant3s
0
336
Member Avatar for lotrsimp12345

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

Member Avatar for Salem
0
111
Member Avatar for fadia

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

Member Avatar for tux4life
0
165
Member Avatar for lotrsimp12345

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 …

Member Avatar for lotrsimp12345
0
113
Member Avatar for athlon32

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

Member Avatar for siddhant3s
0
107
Member Avatar for lotrsimp12345

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 …

Member Avatar for waldchr
-1
85
Member Avatar for nahmartin

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.

Member Avatar for nahmartin
0
138
Member Avatar for kangarooblood

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 …

Member Avatar for bunnyboy
0
111
Member Avatar for Jordaan

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]

Member Avatar for Tom Gunn
0
66
Member Avatar for Alicito

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 …

Member Avatar for tux4life
0
340
Member Avatar for bharanidharanit

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 …

Member Avatar for Dave Sinkula
0
358
Member Avatar for kostasxx

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

Member Avatar for Dave Sinkula
0
132
Member Avatar for MrNoob

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

Member Avatar for Tom Gunn
0
378

The End.