Hello everyone..
I have the following code:
andCode:for (k = 1; k < argc; k++) {
cop = strcmp(argv[k], "-n");
if (!cop) {
size = atoi(argv[k+1]);
}
}
if ((player1 = malloc(size * sizeof(int *))) == NULL) {
printf("\n\nCould not allocate memory!");
return -1;
}
for (k = 0; k < size; k++) {
if ((*(player1+k) = malloc(size * sizeof(int))) == NULL) {
printf("\n\nCould not allocate memory!");
return -1;
}
}
when I run the code, instead of " " it shows NULL and segmentation fault.. Why?Code:for (k = 0; k < size; k++) {
for (j = 0; j < size; j++) {
strcpy(&player1[k][j], " ");
}
}