My first language is Spanish, and my use of English is not the best, but I need some assistance in debugging the following program code since it produces an error when compiled.
CODE:
#include "stdio.h"
int main(int argc, char *argv[])
{ int edad[tope], estatura[tope], rut[tope]; int i; FILE * direccion_de_memoria_del_csv; for (i = 0; i<tope; i++) { printf("=== PERSONA %d ===\n", i); printf("ingrese edad?"); scanf("%d", &edad[i]); printf("ingrese estatura ?"); scanf("%d", &estatura[i]); printf("ingrese rut ?"); scanf("%d", &rut[i]); } /*Nota: c:/tmp/ de existir en el disco*/ direccion_de_memoria_del_csv = fopen("C:/tmp/datos.csv", "w"); fprintf(direccion_de_memoria_del_csv, "edad,estatura,rut\n"); for (i = 0; i < tope; i++) { fprintf(direccion_de_memoria_del_csv, "%d,%d,%d\n", edad[i], estatura[i], rut[i]); } fclose(direccion_de_memoria_del_csv); return 0;
}ERROR:
Taller.c:6:11: error: 'tope' undeclared (first use in this function) int edad[tope], estatura[tope], rut[tope]; ^~~~ Taller.c:6:11: note: each undeclared identifier is reported only once for each function it appears inEXECUTE BY CONSOLE WITH COMMAND gcc Taller.c -o Taller
1 Answer
You did not define tope.
When you initialize your arrays and also when you run through your for-loop the compiler does not know what tope is and therefore cannot determine the size of the arrays. Set it to a constant integer (before you initialize your arrays)
const int tope = 42or just directly put in an integer in the place of tope.
@CentaurusA Sorry for not directly submitting the comment as an answer. It seemed not right at first.