2,827 Posted Topics
Re: The first one uses the "new" operator and therefore uses dynamic memory on the "heap". This memory DOES NOT go out of scope when the line that created goes out of scope. You must free / deallocate that memory with the "delete" operator. This can be a good or bad … | |
Re: Giving the "hint" just made me assume it was one of those trick questions that it wasn't a math question at all but rather something where you sounded out the letters and it made some phrase or whatever. If it's a math problem with no tricks, just state the problem. … | |
Re: Turning on some compile warnings will give you a clue! [quote] gcc dani.c -O -Wall -Wextra -pedantic -Wuninitialized dani.c:2: warning: return type defaults to `int' dani.c: In function `main': dani.c:3: warning: 'side3' might be used uninitialized in this function[/quote] | |
| |
Re: >>Who can calculate tax in C using Control Statement, Arrays, Functions and Pointers... I can! I can! >> if you are so good show me what you Got... OK, I can't resist a dare! I'll show you! Nice try. :icon_rolleyes: | |
Re: All your negative rep seems to come from WaltP and all for the same reason. Read his feedback and take it to heart. That said, everyone deserves a second chance, so you're now positive again. | |
Re: Forget about the programming part for a second. How do you propose to create something curved(sphere) with something that only has straight edges(triangle)? It seems geometrically impossible. Perhaps you are trying to create something "close to" a sphere? >> all of them only describe creating a sphere using some library … | |
Re: You have way too much code involving user input in the same functions as the file reads and writes. If you are advanced enough to use read, write, sizeof, and other fairly low-level function calls, you're advanced enough to partition the program into different segments. This isn't just being nit-picky. … | |
Re: How could decrypting fsdh9hsdg to SetMousePos(X, Y) at runtime help? You don't do anything with the C++ code at runtime. It's too late by then. fsdh9hsdg obviously isn't going to compile. I could see having hard-coded encrypted values in variable assignment code which were decrypted at runtime. I can definitely … | |
Re: I assume it will surprise no one that this is a cross post. [url]http://www.cplusplus.com/forum/general/58817/[/url] | |
Re: It's a scoping issue. See those brackets where you declare c inside of them? You can only use c within those brackets. That's the error. You need to declare c on line 2, not lines 13 and 16. [EDIT] You don't need to declare it on line 2. Declare it … | |
Re: [QUOTE=KingAudio;1730862]I am in an 11th grade computer science class learning C++ and I feel that the class is going to end before I learn how to apply C++. What I want to know is what do I need to learn to start applying C++ into tasks like software development, game … | |
Re: If you have it working for a 3 x 3, post the code for that and perhaps people can offer advice for how to generalize to M x N. | |
Re: >> The following program builds and compiles just fine I'm a little surprised at that. You have array sizes that appear to be based on variables(i.e. unknown at compile time). I haven't worked my way through the program to see if these sizes will always be the same when they … | |
Re: [url]http://www.learncpp.com/cpp-tutorial/810-const-class-objects-and-member-functions/[/url] You have a function called print() which promises to not change an object due to its "const" qualifier. Within that function, it calls a function called getName() which DOES NOT make that promise. So can print() truly make good on its promise to not change anything? No. Think of … | |
Re: [code] #define NULL 0 int main() { int i = 5; int* p = NULL; int* q = NULL; p = &i; //No error as p is assigned the address of i p = *&i; //Error as p is assigned the contents at the address of i p = &*i; … | |
Re: I'll resist the urge to post STFW or post a Let Me Google That For You link. More details are needed, not least of which is what operating system you plan on using and what your knowledge level and skill base is. | |
Re: If you want a DEGREE in Computer Science, it'll require passing quite a few math classes in order to get it. That's if you want the degree. A lot of people seem to do just fine without the degree. | |
Re: It's a bit vague, but this is one of the most common assignments given by C++ professors. They must all get together and decide to give an airline reservation assignment. A search for "airline reservation" will surely get tons of hits. No one uses a database. It adds an unnecessary … | |
Re: The question is impossible to answer without more info from you. We don't know what variables might be needed, we don't know which of them might be global, we don't know if there are any structures set up, we don't know precisely what you need to save in the file … | |
Re: This thread, or actually the other one, gave me a chuckle. It doesn't set the new record for chutzpah, but it ranks up there. Apparently it's not just a cross-post, it's a quadruple post (here, cprogramming, Stack Overflow, bytes.com). I almost want to up-vote it for the brazenness. Nah, down-vote … | |
Re: >> May he rest in peace in heaven. I'd love to see the look on his face if he woke up and found out he was in heaven. | |
Re: Depending on how much memory you have, you may or may not have enough memory to store all the strings in the dictionary in RAM. If you can end up with an alphabetically sorted array of type char* in RAM, that's ideal, at which point you can do quick binary … | |
Re: Lines 17 to 21... [code] fscanf(p, "%s %lu", a, ¶meters[0]); // line 17 parameters[0]=pt1[0]; // line 19 fscanf(p, "%s %lu", a, ¶meters[1]); // line 20 parameters[1]=pt1[1]; // line 21 [/code] Seems like whatever values are read from the file on 17 and 20 are immediately overwritten on lines 19 and … | |
Re: What about the following scenario? 1) Your king is not in check. 2) It's your move and any move you make places your king into check. Is that checkmate? | |
Re: [code] #include <iostream> int main() { //{ int i = 0; while(i < 10) ++i; //} std::cout << i << std::endl; return 0; } [/code] Lines 6 and 10. Brackets commented out = compiles. Brackets uncommented = will not compile. Therefore the issue is the scope of the variable i, … | |
Re: [code] void main() { ifstream inFile; inFile.open("Input.txt"); cout<<"opened"<<endl; system("pause"); } [/code] This is fine. The rest of the code you posted is irrelevant. No function is ever called. How do you know it doesn't open? There is no attempt to read from it and there is no check to see … | |
Re: Read the question again. The word "weight" appears nowhere. The is a math problem and requires you to understand that arrays are contiguous and also how a 2-D array uses the [x][y] pair, starting address, and array size too convert it to an address. presumably there's a formula in your … | |
I've made a small program that draws black rectangles on a JPanel at random places. I would like to give the user the option to save this JPanel as a .gif file, but I'm not sure where to start. The function I need to write is SaveJPanelAsGIF below on line … | |
Re: Forget about whether it's strong encryption or not. I don't see how it can work at all due to two factors... 1) rollover. 2) integer division. 2) Non-prime numbers 1 and 1 are trivial, so these won't come up, but what about a character like '@', which is 64 in … | |
Re: [QUOTE=demroth;562109]I am trying to test the code snippet Lerner created but when I compile I get the following error.... [Linker error] undefined reference to `gToken(std::basic_ifstream<char, std::char_traits<char> >&, std::string*)' ld returned 1 exit status C:\c-- lexical analyzer\Makefile.win [Build Error] ["c--] Error 1 Can anyone tell me just what this error means … | |
Re: >> My question is regarding if i should have the user input a file name they wish to output the information to within main or in another void function Either will work. My general preference in these things is to use a function. It really doesn't matter. I don't see … | |
Re: Code tags and formatting. Your post is impossible to read without them. [noparse] [code] // code here [/code] [/noparse] [ICODE]srand(time(0))[/ICODE] should be called only once at the very top of main. It should not be inside of a loop. Get the [ICODE]system("cls")[/ICODE] calls out of there. It's impossible to debug … | |
Re: Lines 36, 37 and 44 and 45 -- I'm surprised this compiles. You're declaring an array of a variable size, but you are not using the "new" operator. Line 61 -- where did the number 25 come from? Line 63 -- You're assigning a character to equal a string? I'm … | |
Re: Line 31 -- I fail to see the point of calling this function with a negative size value. It does absolutely nothing. Line 41 -- Create a new pizza with uninitialized memory. Lines 42 and 43 -- Display the uninitialized memory. Lord knows what you'll get. I think a string … | |
Re: Line 21 overrides any effect line 17 has. Line 24 and 25 don't make sense. [code] for(j<=100;i>j;++i){ printf("%d", array[n]); }[/code] The loop counter is i, but you are displaying the index n, isn't in the loop and doesn't vary. The initial part of the loop is "j <= 100". I'm … | |
Re: I take it that line 40 executes properly, but line 42 does not? Right off the bat, I see a problem in line 69. size appears to be 100,000, count is assigned to equal size, and first_unsorted can equal anywhere up to 99,999, and that's used in line 69 as … | |
Re: Line 40... [code] for (num_ele current_index = [COLOR="Red"]1[/COLOR]; current_index [COLOR="Red"]<=[/COLOR] input_size; ++current_index) [/code] Indexes start at 0, not 1, and they must be LESS THAN the array / vector size. You simply got lucky when it didn't crash when you entered one string. It could have. You got garbage because … | |
Re: Seems like you should remove the i, not the t. For a 2-D array, I assume you are doing this... [code] matrix[t][i] = temp;[/code] and you want to convert that code. You can either add an element to a vector or change an element that you already have. In your … | |
Re: Copy line 82 into line 13. They need to match and line 13 is wrong. It needs to be "int&", not "&int". The call on line 71 is incorrect. You are passing by reference, which is similar to passing the address behind the scenes, but not the same. You need … | |
Re: >> But with the nested if in place the "code have no effect error" occur. First, I imagine it's a warning, not an error. Depending on compiler flags, warnings may be turned into errors. Second, what line number and what's the exact error message? | |
Re: The sort looks OK to me. What's wrong with the output? And have you verified that everything reads into the structures properly from the file? Note : I assume you have precisely 30 elements? If not, all bets are off because your sort code assumes that. I notice a "peek" … | |
Re: >> use seek? Sure, why not? Seriously, if you want a more useful answer, you'll need to post a much more descriptive question. Your question is unanswerable as written. [EDIT] Perhaps not. Moschops apparently understands what you are asking.. [/EDIT] | |
Re: This actually compiles? [code] [COLOR="Red"]int[/COLOR] months[MONTHS]= {[COLOR="Red"]"01"[/COLOR], "02", "03", "04", "05", "06", "07", "08", "09", "10", "12"};[/code] "01" isn't an integer. | |
Re: [url]http://www.cplusplus.com/reference/string/string/erase/[/url] [quote] pos Position within the string of the first character to be erased. [COLOR="Red"]If the position passed is past the end of the string[/COLOR], an out_of_range exception is thrown. [/quote] I see no checking for this condition and I see no catching of any exceptions, so if this is … | |
Re: Seems fairly straightforward. Don't bother with numbers 2 or 3 till you understand number 1, which you apparently don't, so you need to take a basic tutorial on enumerated types. It's just this. [code] enum Planet {MERCURY, VENUS, EARTH, MARS, JUPITER, SATURN, URANUS, NEPTUNE, PLUTO}; [/code] | |
![]() | Re: The error lines don't match up with the code lines you posted. Lines 115 to 130 -- This is code in the middle of nowhere. Is this supposed to be a function? Ditto lines 132 to 147. Perhaps there are some bracket mismatches? |
Re: [quote] I now need to be able to compare data using the date [COLOR="Red"](string)[/COLOR] and time (unsigned int) as 'sort by' fields. Essentially, I'd like to be able to do something like: [/quote] I'd say that's your problem right there. If you are storing the date as a string and … | |
Re: You posted what the output SHOULD be. What is it actually (I assume it's garbage of some sort, but what kind of garbage?) |
The End.