Just an update
So if I remove [j] from my program, I get a 5x5 grid of "O"'s. This is not ideal however because its just printing the same array 5 times. I want a 25 grid.
This is my current solution which I am not too happy about, I am sure there is an easier and less time consuming way.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int i, j, f, g;
char *board1[25];
int main()
{
for(i = 0; i < 25; i++)
{
if ((board1[i] = malloc(sizeof(char))) == NULL)
{
printf("Memory or array Error\n");
return -1;
}
if(i < 5)
{
strcpy(board1[i], "O");
printf("%s ", board1[i]);
}
if(i == 4)
{
printf("\n");
}
if(i >= 5 && i < 10)
{
strcpy(board1[i], "O");
printf("%s ", board1[i]);
}
if(i == 9)
{
printf("\n");
}
if(i >= 10 && i < 15)
{
strcpy(board1[i], "O");
printf("%s ", board1[i]);
}
if(i == 14)
{
printf("\n");
}
if(i >= 15 && i < 20)
{
strcpy(board1[i], "O");
printf("%s ", board1[i]);
}
if(i == 19)
{
printf("\n");
}
if(i >= 20 && i < 25)
{
strcpy(board1[i], "O");
printf("%s ", board1[i]);
}
if(i == 24)
{
printf("\n");
}
}
}
Bookmarks