Author |
Message |
wtd
|
Posted: Mon Nov 14, 2005 6:54 pm Post subject: (No subject) |
|
|
Well, if you need 26 '8' characters in a string.
c: | #include <stdio.h>
#include <string.h>
int main()
{
char guesses[27];
int guess_number;
for (guess_number = 0; guess_number < 26; ++guess_number)
{
guesses[guess_number] = '*';
}
guesses[guess_number] = '\0';
print("%s\n", guesses);
return 0;
} |
|
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Tubs

|
Posted: Mon Nov 14, 2005 6:57 pm Post subject: (No subject) |
|
|
It isn't supposed to have anything to do with strings, since that is the next chapter in the book. |
|
|
|
|
 |
wtd
|
Posted: Mon Nov 14, 2005 6:59 pm Post subject: (No subject) |
|
|
What course are you taking where they're using C as an introductory language? |
|
|
|
|
 |
Tubs

|
Posted: Mon Nov 14, 2005 7:04 pm Post subject: (No subject) |
|
|
First year university programming. I have turing background from highschool though. |
|
|
|
|
 |
wtd
|
Posted: Mon Nov 14, 2005 7:08 pm Post subject: (No subject) |
|
|
Wow. That's an awful university. |
|
|
|
|
 |
Tubs

|
Posted: Mon Nov 14, 2005 7:13 pm Post subject: (No subject) |
|
|
Thanks. Thats not helping my problem though. |
|
|
|
|
 |
wtd
|
Posted: Mon Nov 14, 2005 7:14 pm Post subject: (No subject) |
|
|
Well, without seeing the problem we have no idea what you're trying to accomplish, so we can't help you very well. The problems could be in any one of several different areas. |
|
|
|
|
 |
Tubs

|
Posted: Mon Nov 14, 2005 7:15 pm Post subject: (No subject) |
|
|
I posted the problem if you would look. |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
wtd
|
Posted: Mon Nov 14, 2005 7:26 pm Post subject: (No subject) |
|
|
Ok, if you didn't know that arrays in C are indexed starting at zero, then I seriously suggest you go to your professor and ask for help. Not knowing that indicates to me that you're unprepared to write that program, and trying to just jump in and make wild stabs at it is just going to confuse you further. |
|
|
|
|
 |
Tubs

|
Posted: Mon Nov 14, 2005 7:31 pm Post subject: (No subject) |
|
|
That wasn't that problem at all, mostly I was just confused on why my for statement was not working. |
|
|
|
|
 |
wtd
|
Posted: Mon Nov 14, 2005 7:35 pm Post subject: (No subject) |
|
|
That actually was a major problem. If you have an array with 26 elements, the last index is 25. You were trying to write to index 26. That is a big problem, and it's a fundamental lack of knowledge about how arrays work in C kind of problem. |
|
|
|
|
 |
Tubs

|
Posted: Mon Nov 14, 2005 7:37 pm Post subject: (No subject) |
|
|
It is the first time I have written arrays in C and I overlooked it... let it go. |
|
|
|
|
 |
wtd
|
Posted: Mon Nov 14, 2005 7:39 pm Post subject: (No subject) |
|
|
What I'm saying is that it's something you should have been taught before being asked to write a program like that. If you weren't, then there are likely other problems waiting to come back and bite you, and you should talk about it with your professor. |
|
|
|
|
 |
Tubs

|
Posted: Mon Nov 14, 2005 7:44 pm Post subject: (No subject) |
|
|
Its not something I didn't know, it was simply overlooked like typing 'print' instead of 'printf'. If you are just going to criticize my school and knowledge of C instead of help, don't bother posting. |
|
|
|
|
 |
wtd
|
Posted: Mon Nov 14, 2005 7:59 pm Post subject: (No subject) |
|
|
I'm not criticizing you for the 1..26 thing. I am saying that it's such a basic thing that it suggests other problems. I've seen lots of other people with the same issue, and in every case there have been a lot of other basic misconceptions that weren't caught early on and because of that had a tendency to snowball.
Kind of like building a rocket, and you get the whole thing constructed and put into firing position and the electrical system fully debugged before anyone bothers to point out that it should be pointing up.
As for this particular problem, you're storing a word to be guessed as a series of characters in an array. You're then creating a second array with 26 elements. Presumably it's not a coincidence that there are also 26 letters in the alphabet.
How does having this array fit into solving the problem of creating a simple hangman game?
Do you know how to check to see if the word has been guessed, which would end the game?
Do you know how to check to see if every possible letter has been guessed, which would also end the game? |
|
|
|
|
 |
|