: 나는이 프로그램이 단지 위치 "tnome[0][0]"
를 저장하는 코드를 실행하면매트릭스 하나 개 이상의 값 코드입니다
int qtd_alunos, qtd_temas;
char* tnome[1][10];
char* anome[1][10];
printf("\nPra distribuir os temas me diga quantos alunos vao participar e aperte enter, depois a quantidade de temas.");
scanf("%d%d", &qtd_alunos, &qtd_temas);
printf("Agora vai escrevendo o nome de cada tema\n");
for(int j = 0; j<qtd_temas; j++){
printf("Tema %d\n", j+1);
scanf("%s", tnome[0][j]);
printf("%s ok!\n",tnome[0][j]); }
return 0; }
하지만 때 프로그램이 종료 [0][1]
에 "int j"
변경됩니다. 나는 그것이 왜 일어나는 지 이해할 필요가있다.
(https://stackoverflow.com/questions/2614249/을 형식 문자열에
scanf
에 의해 판독 된 문자열 의 크기를 제한 할 수 있습니다 동적 메모리를위한 2 차원 문자 배열)에 대한 해답은 [this] (https://stackoverflow.com/questions/18083984/how-to-store-and-then-print-a-2d-character)입니다. -string-array) 대답으로 충분할 것입니다. – Yahya이 질문과 같이 런타임 문제를 묻는다면'scanf()'함수 군을 호출 할 때 [mcve] – user3629249
을 게시하십시오 : 1) 항상 매개 변수 값이 아닌 반환 값을 확인하여 확신하십시오 수술은 성공적이었다. 2) '% s'또는 '% [...]'입력 변환 지정자를 사용할 때 항상 입력 필드의 길이보다 하나 작은 MAX CHARACTERS 수정자를 포함하십시오. 왜냐하면'scanf()'는 항상 그 지정자에 NUL 바이트를 추가하기 때문입니다. – user3629249