나는 단어 검색 프로그램을 만들고 있으며, 시작 단계에 있습니다. 사용자가 단어 검색에 들어가는 단어를 입력하기 전에 사용자가 '+'크기의 그리드를 입력하게하려고합니다. 프로그램을 실행할 때 '+'하나만 인쇄합니다. 왜 단지 하나의 값만 인쇄하고 모든 값이 '+'로 표현되도록 코드를 조정해야합니까? 나는 프로그래밍 초보자이므로 조언이 도움이 될 것입니다. 감사합니다.왜 내 2D 배열은 하나의 값만 인쇄합니까?
#include<stdio.h>
void printmatrix(char matrix[][20],int);
int main(void)
{
char matrix[20][20]= {{'+'}};
int x=1;
printf("How large would you like the puzzle to be (between 10 and 20):\n");
scanf("%d",&x);
printmatrix(matrix,x);
return 0;
}
/********************************************
Function Name: Printmatrix...this function prints out an empty matrix of the grid size the user asked for
Inputs: Variables x and y...the row and column variables the user inputted
Outputs: Empty matrix filled with '+' thats the size the user asked for
********************************************/
void printmatrix(char matrix[][20],int x)
{
int i,j;
printf("Empty Puzzle:\n");
for (i=0;i<x;i++)
{
for (j=0;j<x;j++)
{
printf("%c", matrix[i][j]);
}
printf("\n");
}
}
이전에이 작업을했지만 프로그램의 나중 단계에서이 행렬의 특정 값을 사용하여 단어를 삽입해야합니다. – user3376431