char pointer allocates random characters
I am writing a small C code for class that plays Hangman with an already
input name. One section requires I allow the output of the input phrase
with * in the place of all letters, but not punctuation. Similarly, at the
end of the phrase, the name of the user is put in parentheses and is meant
to be printed as is. The first section of the code works fine, the first
while loop which places the asterisks, but the second while loop seems to
fail every time and seems to store nonsense and random characters
everytime the program is run. Here is the program I have so far.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int guesses = 3;
int limit = 41;
char quote[42] = "I just wrote this game in C! (Josh Masher)";
char strArr[42];
char *quoP;
quoP = "e[0];
char *strP;
strP = &strArr[0];
while (*quoP != '.' && *quoP != '!' && *quoP != '?') {
if (isalpha(*quoP)) {
*strP = '*';
} else if (*quoP == ' ' || *quoP == ',') {
*strP = *quoP;
}
strP++;
quoP++;
}
while (*quoP != NULL) {
*strP = *quoP;
strP++;
quoP++;
}
}
any ideas?
No comments:
Post a Comment