Dunno - works for me.
Code:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
void initializeboard(char plyr1board[][10], int numrows, int numcolumn)
{
int rowindex = 0, clmnindex = 0;
for (; rowindex < numrows; ++rowindex)
{
for (clmnindex = 0; clmnindex < numcolumn; ++clmnindex)
{
plyr1board[rowindex][clmnindex] = '~';
}
}
}
void printboard(char plyr1board[][10], int numrows, int numcolumn)
{
for ( int r = 0 ; r < numrows ; r++ ) {
for ( int c = 0 ; c < numcolumn ; c++ ) {
printf("%c",plyr1board[r][c]);
}
printf("\n");
}
}
int main ( ) {
char plyr1board[10][10];
int direction,c1,c2;
initializeboard(plyr1board,10,10);
printf("\n\nEnter direction you would like to place your Carrier: \n\n1. Vertical\n2. Horizontal\n\nSelection: ");
scanf("%d", &direction);
if (direction == 1)
{
printf("\n\nEnter coordinate where you would like to place Carrier: ");
scanf("%d%d", &c1, &c2);
while (c1 > 5)
{
printf("\n\t\t\t\tDon't send your men into the abyss! Stay within the board (5 Spaces)\n\n");
printf("Enter coordinate where you would like to place Carrier:");
scanf("%d%d", &c1, &c2);
}
for (int a = c1, q = 0; q < 5; ++q, ++a) //q represents the size of the carrier (5), once 4 is reached, a should stop incrementing as well
{
plyr1board[a][c2] = 'C'; //a = row, c2 = column (for vertical, column shouldn't change)
}
}
printboard(plyr1board,10,10);
}
$ gcc -g foo.c
$ ./a.out
Enter direction you would like to place your Carrier:
1. Vertical
2. Horizontal
Selection: 1
Enter coordinate where you would like to place Carrier: 4 2
~~~~~~~~~~
~~~~~~~~~~
~~~~~~~~~~
~~~~~~~~~~
~~C~~~~~~~
~~C~~~~~~~
~~C~~~~~~~
~~C~~~~~~~
~~C~~~~~~~
~~~~~~~~~~
Perhaps like I did, you should post an actual complete program which replicates your observation, not just random snippets which prove absolutely nothing one way or another.