segmentation fault !!!

hey,
In the main part, I get the segmentation fault error while going to the next part of this,
for (int j = 0; j < strlen(*guess); j++) {

for (int z = 0; z < strlen(*guess); z++) {
if (*guess[j] == *secret_number[z])
cows++;
}
if (*guess[j] == *secret_number[j])
bulls++;

}
Last edited on
1
2
int comparenum;
comparenum = (int)malloc(16);


This makes no sense. What are you trying to do here. This makes no sense.
yes I removed that part but the result did not change I rearranged my question
Presumably, you're accessing invalid memory. Either you're dereferencing a pointer to invalid memory, or you're trying to access beyond the memory allocated for one of your arrays.

You really haven't shown us enough code for us to know.
It depends entirely on how you have your memory laid out.

What exactly is guess?
if strlen(*guess) compiles, that means that guess is a char** of some sort.

guess[i] might not even be valid data, but we can't tell without knowing more.
You might have meant to do (*guess)[i] or guess[0][i] to access individual characters, but it's very odd.
Last edited on
Get rid of all this pointer stuff and stick with char arrays.
I guess this is related to a previous topic about cows and bulls.
Topic archived. No new replies allowed.