First, your indentation needs work.
Code:
#include <stdio.h>
#include <math.h>
#include<string.h>
#include<stdbool.h>
#include<stdlib.h> //!! malloc is here, not in malloc.h
int main(void)
{
void record(char *response, char *guess, int NOG, int length, char **matrix);
void check(char *key, char *guess, char *response, int length);
int t;
printf("Enter the pattern length");
int length;
scanf("%d", &length);
printf("Enter the number of guesses");
int limit;
scanf("%d", &limit);
char *response;
response = (char *) malloc((length + 1) * sizeof(char *));
char guess[length];
printf("Input the key pattern with no spaces:");
char key[length + 1];
scanf("%s", key);
int NOG = 0;
//response to generate the bww thing
char **matrix; //for printing the result
matrix = (char **) malloc(2 * limit * sizeof(char *));
for (t = 0; t < limit; t++)
matrix[t] = (char *) malloc((length * 2 + 1) * sizeof(char));
//making 2 dimentional array 'matrix'
int j, w, k, g, c;
do
{
printf("Input a guess pattern with no space:");
scanf("%s", guess);
check(key, guess, response, length);
int counts;
counts = 0;
for (j = 0; j < length; j++) {
matrix[NOG][j] = response[j];
}
matrix[NOG][j] = ' ';
for (k = length + 1; k < length * 2 + 1; k++) {
matrix[NOG][k] = guess[k - length - 1];
}
for (w = 0; w < NOG + 1; w++) {
printf("%d: ", w + 1);
for (g = 0; g < length * 2 + 1; g++) {
printf("%c", matrix[w][g]);
}
printf("\n");
}
NOG++;
}
while (strcmp(guess, key) && NOG != limit);
return 0;
}
void check(char *key, char *guess, char *response, int length)
{
int j, k, n, m, t, z, x, w, i;
k = 0;
int counts = 0;
bool *badj;
for (t = 0; t < length; t++)
badj[t] = (bool *) malloc((length) * sizeof(bool));
for (n = 0; n < length; n++)
badj[n] = 1;
bool *bads;
for (w = 0; w < length; w++)
bads[w] = (bool *) malloc((length) * sizeof(bool));
for (z = 0; z < length; z++)
bads[z] = 1;
for (x = 0; x < length; x++) {
if (key[x] == guess[x]) {
response[k] = 'b';
counts++;
bads[x] = 0;
k++;
}
}
for (i = 0; i < length; i++) {
if (bads[i] == 0)
continue;
for (j = 0; j < length; j++) {
if (badj[j] == 0) {
continue;
}
else if (key[i] == guess[j]) {
response[k] = 'w';
counts++;
badj[j] = 0;
k++;
}
}
}
for (m = counts; m < length; m++) {
response[k] = '.';
k++;
}
response[k] = '\0';
printf("%s", response);
}
Second, compile with lots and lots of warnings enabled.
Code:
$ gcc -W -Wall -Wextra foo.c
foo.c: In function ‘main’:
foo.c:45:9: warning: variable ‘counts’ set but not used [-Wunused-but-set-variable]
foo.c:37:19: warning: unused variable ‘c’ [-Wunused-variable]
foo.c: In function ‘check’:
foo.c:80:9: warning: ‘badj’ may be used uninitialized in this function [-Wuninitialized]
foo.c:86:9: warning: ‘bads’ may be used uninitialized in this function [-Wuninitialized]
The last two are killing your program.
Code:
bool *badj;
for (t = 0; t < length; t++)
badj[t] = (bool *) malloc((length) * sizeof(bool));
You need to make badj point to something, before using badj[t]
Third, this is C code, so you can remove the casting on the malloc return.