1,359 Posted Topics
Re: Before we get to the specific issue, I'd like to mention a few things. First, it is incorrect to use `void ` as the return type of the `main()` function; according to the C++ language standard, you should always use `int main()`. Some compilers do allow `void main()`, but strictly … | |
Re: What have you tried so far? Show us your code - or just some pseudo-code - and we'll help you debug it. If you aren't sure where to start, start by figuring out how you are going to read in a given line of text and parse it. I recommend … | |
Re: On the one hand, I agree with veedoo regarding the use of a general-purpose editor; it is often better to have one editor which you are well-familiarized with, than to jump between different editors based on the language. OTOH, there are always circumstances where you won't be able to use … | |
Re: Could you tell us more about what you've tried already? I know that it isn't C, but you might want to look at the circuit simulation code in Chapter 3 of [*Structure and Interpretation of Computer Programs*](http://mitpress.mit.edu/sicp/). It goes into detail about how the circuit connections can be implemented, and … | |
Re: To post a code sample, you can use the Code button on the editing bar just above the editing pane. This should open up a new window where you can paste the code samples. Alternately, you can simply indent the line four spaces, with extra lines between the code and … | |
Re: Programmatically, you mean? What is your intention with it? If this is a one-time deal, you might be better off just using the hex editor. Also, what compiler are you using, and does it have any sort of library available for this purpose? Do you you intend to manipulate the … | |
Re: Again with putting code in the header files... *sigh*. Worse, it is now clear that this horrible practice is being perpetrated and perpetuated by your instructor, who apparently wrote the majority of said code in this fashion, leaving only sections for you to fill out. <rant> Either your professor is … | |
Re: First off, stop using the SMS abbreviations; no one will take you seriously here if you insist on that sort of thing. Write out clear, complete English sentences, to the best of your ability, please. Second, while I know it is a picayune point to make, `void main()` is not … | |
Re: In addition to Trentacle's questions, I would also ask, what compiler are you using, under what kind of system? The reason I ask is because, while a ten million item array is almost certainly excessive, it should be *possible* to declare and use one under a modern 32-bit or 64-bit … | |
Re: Uhm... just what did you want to know, or needed help with? | |
Re: I would recommend starting off with the representation of the deck of cards. Have you studied classes and object-oriented programming yet? If you have, then the easy thing to do is create a class Card, which can have one of the 52 face and suit values, then use that to … | |
Re: To get the crux of the problem, take another look at what the `for()` loop does in each of it's four parts. Here is a simplified version of the [BNF](http://en.wikipedia.org/wiki/Backus%E2%80%93Naur_Form) grammar of the `for()` expression: <for_loop> ::= 'for (' <initialization> ';' <conditional> ';' <increment> ')' <body> Compare this to the … | |
Re: OK, first things first: I know that you were probably instructed to put the functions in the header file, but in fact you only want the function *prototypes* declared there; you'll want to put the actual functions in a third file, which would then be linked into the program at … | |
Re: The structure as given makes no sense; I suspect what you want is more on the order of this: typedef struct dynamic_array { size_t array_size; int* array; } DYNAMIC_ARRAY; The idea here is that you have a `size_t` variable to hold the number of elements in the array, and then … | |
Re: I would actually recommend using [template specialization](https://www.google.com/webhp?source=search_app#q=template+specialization&fp=1) and the [string::find()](http://www.cplusplus.com/reference/string/string/find/) method instead: template<> bool CustomType<std::string>::Contains(const std::string& literal, bool CaseSensitive) { std::string s(literal); if (!CaseSensitive) { for (size_t i; i < s.size(); i++) { s[i] = tolower(s[i]); } } return this->find(s); } template<> bool CustomType<char *>::Contains(const char* literal, bool CaseSensitive) { … | |
Re: OK, let's start with the basics. In general, the first step in parsing a stream of text is to break the text up into lexemes (tokens), right? So, what you want to do is work out the basic components of the input format, write a simple lexical analyzer to tokenize … | |
Re: Actually, there's still a problem with it; the [formatting string](http://www.cplusplus.com/reference/clibrary/ctime/strftime/) is incorrect, which means that the time string never gets created. The correct format should be `"%I"` for hours (12-hour format) and `"%M"` for minutes. Try the following: #include <iostream> #include <cstdio> #include <ctime> using namespace std; const int Buffer_Size … | |
Re: Ordinarily, the best solution for primes under about 1 million would be to use the [Sieve of Eratosthenes](https://www.google.com/search?q=sieve+of+eratosthenes) to generate all of the primes from 2 to the upper bound number. Given that the sieve *requires* that you start at 2, however, it may not be what your professor is … | |
Re: The reasons why it is crashing is quite simple: first off, you are only allocating one structure's worth of memory in your call to `calloc()`. When you try to access the (non-existent) second structure, you run off the end of the allocated array, causing a memory protection violation. My recommendation … | |
Re: I am somewhat puzzled by the use of this loop to print out the two different strings in `card[][]`: for(int x=0;x<19;x++) { printf("%c",card[i][x]); if(card[i][x] == ':') { fgets(&face[i],3,stdin); } } Wouldn't it be just as easy to use printf("Enter suit value for %s ", card[i]); face[i] = getchar(); getchar(); /* … | |
Re: While I have only looked at this briefly, I can tell you that the main problem stems from this error here: > main.c|75|warning: implicit declaration of function '`get_endereco`'| What this means is that you haven't declared the function `get_endereco()` at that point of the source file yet, and the compiler … | |
Re: In the absence of the necesary information from the OP, I can only make broad suggestions, with the number one recommendation being to replace all of these repetitive tests with a table and simple loop. struct Q_and_A { std::string question; std::string options[3]; char answer; int points; }; Q_and_A exam[] = … | |
Re: First off, we don't do other people's homework for them. Second, we don't do other people's homework for them. And third, we don't do other people's homework for them. Sensing a pattern here yet? No one here will simply hand you a solution on a silver platter. If you show … | |
Re: lucaciandrew: I have to disagree with you on this - the fully qualified `std::string` is generally preferable to `using namespace std;`, especially inside headers. Headers get included in multiple locations, some of which could present namespace collisions if you have the `std` namespace (or any other, for that matter) used … | |
Re: OK, what problem are you having? The code your instructor provides is pretty straightforward (if a bit [BFI](http://www.catb.org/jargon/html/B/brute-force-and-ignorance.html), presumably on purpose) and should be easy to extend. Where is the issue, and what is it doing wrong? | |
Re: Looking at [this page in MSDN](http://msdn.microsoft.com/en-us/library/x70d7t0y.aspx#Y0) I believe you want to use either `Convert::ToString(makebreak)` or the equivalent `Int32::ToString(makebreak)`. | |
Re: While the point about your code was broadly speaking correct, the explanation given is a bit off. It isn't so much how the *pointer* was declared or assigned as much as it is about how the *memory* it points to was allocated, and how long you need that memory to … | |
Re: It's very unlikely that the characters are going to appear as you want them to, for a console application. You would need a [code page](http://en.wikipedia.org/wiki/Code_page) which has the appropriate glyphs, mapped to the correct Unicode [code points](http://en.wikipedia.org/wiki/Code_point). While there are Unicode code pages for UTF-7, UTF-8, and UTF-16, I don't … | |
Re: First off, you might want to use [`calloc()`](http://www.cplusplus.com/reference/clibrary/cstdlib/calloc/) rather than `malloc()` for allocating arrays: ascii=(int *)calloc(24000, sizeof(int)); It's a minor point, as there is no real difference in it result-wise, but it does make it clearer what your intent is. Also, you are allocating memory and having `enc` and `dec` … | |
Re: Can you please tell us what you need help with? Aside from indent style issues, I mean. | |
Re: Could you tell us what the errors you are getting are, as well as which compiler and platform you are using? One thing I will recommend right off the bat is to remove the `using namespace std;` from both the header and the implementation file for your class, and explicitly … | |
Re: As Deceptikon says, the languages themselves are not software at all. Presumably, what you want to know about are the translators - compilers and interpreters - which implement the languages. The answer is, 'yes'. Whether they are system software or application software is entirely a matter of point of view. … | |
Re: Well, first off, it isn't really the case that composition is *superior* to inheritance, so much as that they are useful for different things, and that inheritance lends itself to misuse more than composition does. The real knock against inheritance is about '[spaghetti inheritance](http://catb.org/jargon/html/S/spaghetti-inheritance.html)', which is where you are inheriting … | |
Re: The `endl` manipulator has the effect of forcing a newline. If you remove it from the output line, and put it after the end of the loop, it should give the desired result: for(int i=0; i <= 10; i++) { cout << i; if (i < 10) { cout << … | |
Re: Which DBMS are you using? Most modern database engines have some sort of support for autoincrementing integers, which would make a lot more sense for most purposes than a text field as a primary key. | |
Re: First off, you want to change how you are setting the first day of the month. Right now, you have a fixed offset for the first day, and are then using that same offset for each successive day of the month, causing them to be printed at intervals of 36 … | |
Re: Calling `main()` explicitly is an extremely poor idea; in fact, it is actually forbidden in the C++ standard, and the compiler ought to be giving you an error message on that (not that all compilers do). The `main()` function is special in a number of ways - it performs a … | |
Re: There are a number of mistakes in this code, starting with the use of `void main()` rather than `int main()`. While the older C standard allows for it, it is a non-portable variant, and the IIRC newest version of the standard closes that loophole by requiring `main()` to return an … | |
Re: First off, they are completely unrelated languages; Java was developed out of a language called Oak by Sun Microsystems, while JavaScript was created by Netscape Communications. while they share some common syntax, most of that commonality was inherited independently from C++. 'JavaScript' isn't even the original name of the language … | |
Re: Best is awfully subjective, but I can make a few suggestions. To start with, the [main Python site](http://www.python.org) actually has some excellent tutorials, as well as all of the documentation references for the language. The [Dive Into Python](http://www.diveintopython.net/) online text is a good one if you are already familiar with … | |
Re: Ah, now this is a different question. In C/C++, any given *program* must have exactly one `main()` function, but a program may span as many *files* as you like, and not all source files must have a `main()` - indeed, most source files won't, for the majority of non-trivial projects. … | |
![]() | Re: The main thing I am seeing here is that you are trying to save the characters to `int` variables, rather than `char`. While it is true that the standard `char` type is only 8 bits wide, and thus would not be able to hold the multi-byte characters, using an `int` … ![]() |
Re: [Cross-posted to DevShed](http://forums.devshed.com/other-programming-languages-139/task-in-assembler-8086t-909850.html#post2786932) [Also Warrior Forums](http://www.warriorforum.com/programming-talk/609727-task-assembler-8086-a.html) I posted some comments on the DevShed thread which I hope you'll find useful; I would repost them here, but it would just be a waste of the disk space for Daniweb to duplicate it. Suffice it to say, you need to give us … | |
Re: We can help you debug the program, certainly. We won't 'help' you by doing it for you. The code as given is far from a working program; the most obvious problem with is the inconsistent use of capitalization, which in a case-sensitive language is an error. That is to say, … | |
Re: On a casual scan, I see that the section where you test for the input value being a letter can be simplified by using the [`isalpha()` function](http://www.cplusplus.com/reference/clibrary/cctype/isalpha/) (actually, it's usually implemented as a macro, but that's besides the point). while (isalpha(inpLetter)); On a related note, the [`toupper()`](http://www.cplusplus.com/reference/clibrary/cctype/toupper/) and [`tolower()`](http://www.cplusplus.com/reference/clibrary/cctype/tolower/) functions … | |
Re: OK, sounds like a good project to work on. What have you done with it so far? | |
Re: Setting the overall goal aside for the time being, what it sounds like is that you want help in processing [command-line arguments](http://www.crasseux.com/books/ctutorial/argc-and-argv.html). While the details of this can be rather tricky, the basics are fairly straightforward. In C and C++, command-line arguments are passed to the program as a pair … | |
Re: The MOV instruction is for moving (copying, actually) a value from one memory location to another (or from memory to a fast register, which is sort of special kind of memory for performing operations in quickly and for holding special values the system needs to keep track of, or vice … | |
Re: How is it getting corrupted? Just what is the problem behavior? Now, I should mention that the way you have the `for()` loops indexed is potentially problematic, because you are starting at 10 on each of them. Why would this be a problem? Because a ten-element array would have indices … | |
Re: I have to agree with WaltP; if you are writing a simple program that resembles a language interpreter, and it is capable of computing non-trivial equations of more than a fixed size, then you really are talking about writing an intepreter. You'll want to go the whole route of tokenizing … |
The End.