-
-
Save parzibyte/438ba19c7e98bfa040cc6b969b9f08eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Arreglo de cadenas: aquí almacenamos todas las palabras | |
char palabras[CANTIDAD_PALABRAS][MAXIMA_LONGITUD_CADENA]; | |
// Útil para leer el archivo | |
char buferArchivo[MAXIMA_LONGITUD_CADENA]; | |
// Abrir el archivo... | |
FILE *archivo = fopen(NOMBRE_ARCHIVO, "r"); | |
if (archivo == NULL) | |
{ | |
printf("No se puede abrir el archivo"); | |
return 0; | |
} | |
// Necesitamos este ayudante para saber en qué línea vamos | |
int indice = 0; | |
// Mientras podamos leer una línea del archivo | |
while (fgets(buferArchivo, MAXIMA_LONGITUD_CADENA, archivo)) | |
{ | |
// Remover salto de línea | |
strtok(buferArchivo, "\n"); | |
// Copiar la línea a nuestro arreglo, usando el índice | |
memcpy(palabras[indice], buferArchivo, MAXIMA_LONGITUD_CADENA); | |
// Aumentarlo en cada iteración | |
indice++; | |
} | |
// Terminamos de leer | |
fclose(archivo); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment