![]() |
|
#1
|
|||
|
|||
string and reference confusionBelow is my semi-finished program..
I have a couple of issues that have me stuck, and after looking up several different ways to solve them, I'm still stuck. - The reference I'm using for &nameLoc doesn't seem to be passing, because the output for Byfuglien is always from the 0 element. I'm not sure how to properly increment a search in the playerSearch function at the very end. - When I try to input a different name that doesn't exist within the players[], the program loops infinitely and my compiler essentially crashes. I would definitely appreciate any insight to what I could change, and what I'm doing wrong. (Preferably not a direct solution, just a push in the right direction.) Thanks in advance. CPP / C++ / C Code:
|
|||
|
#2
|
||||
|
||||
Re: string and reference confusionI've got an idea...how about giving us only part of the problem and seeing if we can come up with our own "players.txt" input file from your code...you know, just as an exercise to see how good we are and how much time we have available to help you solve your problems?
I'm wondering why your "coding style" has the following: CPP / C++ / C Code:
...you put a space between the function names and the parens in some cases, then in some other cases you don't...such as "exit(0)" and "setw(...)" and "setiosflags(...)" and some of your own functions such as buildArrays, sortArrays and printArrays? You may want to decide on one or another style and be consistent throughout all of your code. While you're always "free" to create your own style, using an existing, "standard" style is probably a better choice while you're learning. A typical convention is to not use a space between the function name and the parenthesis but to use a space between the parenthesis of NON functions such as in the case of conditionals: CPP / C++ / C Code:
Additionally, I'd recommend that you treat every conditional statement as a "multiline" conditional. That is, use "{" and "}" for every single if, for, while, etc. It is a good habit to get into. I'd probably recommend that you avoid global data as much as possible...at least for now. When you better understand its virtues and vices, then you will be ready to selectively apply it. So, if you want to send us at least a portion of the players.txt content, we may have the energy to revisit this problem. Of course, anyone else is welcomed to solve it without it. Lastly, you say that "my compiler crashes." I find that extremely difficult to believe. Perhaps you mean that your IDE crashes? One of the biggest issues programmers have to encounter is being specific. That means "exacting." The "computer" will do exactly what you program it to do within the context of its operating environment. My guess is that you executed the compiler LONG (really, really long in terms of processor cycles) before you actually executed your code and that the compiler execution terminated successfully long before the linker was invoked and successfully terminated and long before you could even move the mouse (or press hotkeys) to begin execution of your program. While it is not a "sin" to use "compiler" as a synonym for your toolchain (a collection of tools that enable you to easily build, debug and execute programs), it may be useful for you to begin using the most accurate explanations of what happens as early in your career as possible...even if the "extent" of your career is only a semester long C++ course. By indicating exactly what happened, you also earn the confidence of other programmers. MxB |
|
#3
|
|||
|
|||
Re: string and reference confusionMy apologies, for the mistakes I make in your eyes don't seem to be mistakes from my perspective just yet.
In regards to the code that opens the file and outputs an error if it didn't open, it's something required for the program. As for the formatting of my code, I didn't even realize that I had been inconsistent, but thank you for pointing that out, it will be something that I keep in mind from now on. The players.txt file is the following group of numbers -- the first column is the number for goals, followed by assists and finally shots. Code:
I personally didn't feel that this would be entirely relevant to the assistance for which I was asking.. Though, now in retrospect I realize that if you were to offer any assistance, you would need the file to utilize the code I wrote.. otherwise it's like trying to drive blindfolded. - To be a bit more specific, my compiler doesn't crash. I also didn't realize this would cause confusion. Essentially, when I compile and build the program, there are no errors. When I execute the program, however, the result is as if I had coded an infinite loop, and after about 3-4 seconds, I get a message from windows notifying me that quincy2005 has stopped working. This happens if I change "Dustin Byfuglien" to my own name, or any name that isn't initialized as an element into the players[] array. -- I don't mean to sound too defensive, and I greatly appreciate your criticism and advice. I'll never learn if I don't make mistakes, so thanks for your patience in looking over my code, and thanks in advance if you happen to look over it again. -Justin |
|
#4
|
|||
|
|||
Re: string and reference confusionAfter looking over my code again in an attempt to understand what I was doing wrong, I figured it out.
- My first mistake was not assigning a value to nameLoc to be 'passed back' to int main(). - My second mistake was in the same function, where I had typed CPP / C++ / C Code:
CPP / C++ / C Code:
and now it's working just fine. |
|
#5
|
||||
|
||||
Re: string and reference confusionQuote:
You may want to take a look at the following resource: Gimpel On-Line Demos Gimpel has an online version of their tools available that evaluates C and C++ code (separate links per language) and, as shown below, finds these same errors that you found. Output: Code:
...note that I believe that this constitutes a fair use of their copyrighted work in as much as I quoted the source and recommend their products for those kinds of programmers for which their software targets and benefits. Check the Gimple Software site for more details about using their products. MxB |
Recent GIDBlog
Problems with the Navy (Chiefs) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problem executing nam-1.13 | RodolfoAlvizu | Computer Software Forum - Linux | 20 | 28-Feb-2009 16:23 |
| gzip linker problem boost::iostreams with zlib | J-M | C++ Forum | 2 | 29-Apr-2008 05:00 |
| Assigning string to NULL value | amdrulz | C Programming Language | 5 | 10-Oct-2006 00:33 |
| can anyone help me with this? | chasey | Java Forum | 38 | 31-Jul-2006 11:33 |
| a tester class and then some. | postage | Java Forum | 1 | 06-May-2006 16:48 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The