Мне нужно следующую функцию в языке c, которая прибыть в элемент: array[i][1][1]
и просить, чтобы он ввел информацию, программу у пользователя прекращает функционировать.
int introducir_resultados(int array[NUMMUNICIPIOS][NUMPARTIDOS][3], int num_municipios, int num_partidos)
int n, i, num_votos, num_candidatos, num_candidatos_no;
for (i=0;i<num_municipios;i++)
{
printf("****Municipio %d****\n\n", i);
for(n=0;n<num_partidos;n++)
{
printf("Introduzca numero de votos para el partido %d\n", n);
scanf("%d", &num_votos);
array[i][n][0] = num_votos;
printf("Introduzca numero de candidatos elegidos del partido %d\n", n);
scanf("%d", &num_candidatos);
array[i][n][1] = num_candidatos;
printf("Introduzca numero de candidatos no elegidos para el partido %d\n", n);
scanf("%d", &num_candidatos_no);
array[i][n][2] = num_candidatos_no;
}
}
return array[num_municipios][num_partidos][3];
Кто-то знает, что он может вызывать ошибку? Спасибо заранее из-за помощи.
Я присоединяю метод main () и заявление функций, если он следует из помощи, чтобы решать мой вопрос, спасибо.
#define NUMMUNICIPIOS 10
#define NUMPARTIDOS 10
int menu();
int introducir_resultados(int array[NUMMUNICIPIOS][NUMPARTIDOS][3], int num_municipios, int num_partidos);
void visualizar_municipio(int array[NUMMUNICIPIOS][NUMPARTIDOS][3], int num_municipios, int num_partidos);
int main()
{
int num_municipios, num_partidos, opcion, array[NUMMUNICIPIOS][NUMPARTIDOS][3];
opcion = menu();
if (opcion == 1)
{
printf("Introduzca numero de municipios (max = 10)\n");
scanf("%d", &num_municipios);
while (num_municipios > NUMMUNICIPIOS)
{
printf("Introduzca un numero valido\n");
scanf("%d", &num_municipios);
}
printf("Introduzca numero de partidos (max = 10)\n");
scanf("%d", &num_partidos);
while (num_partidos > NUMPARTIDOS)
{
printf("Introduzca un numero valido\n");
scanf("%d", &num_partidos);
}
array[NUMMUNICIPIOS][NUMPARTIDOS][3] = introducir_resultados(array[NUMMUNICIPIOS][NUMPARTIDOS][3], num_municipios, num_partidos);
}
FГ-jate, что funciГіn возвращает одну posiciГіn не vГЎlida:
return array[num_municipios][num_partidos][3];
// ^ valores validos: 0, 1, 2
С другой стороны, не надо, чтобы ты использовал временную переменную, чтобы читать ввода estГЎndar, ты можешь хранить информацию прямо в array:
// Cambia esto
scanf("%d", &num_votos);
array[i][n][0] = num_votos;
// Por esto
scanf("%d", &array[i][n][0]);
Из-за этого demГЎs я не вижу другие ошибки. Если это return
не решает твоя проблема deberГЎs предоставлять пример mГ-nimo и полно, что позволил нам воспроизводить ошибку