Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created October 30, 2020 01:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/438ba19c7e98bfa040cc6b969b9f08eb to your computer and use it in GitHub Desktop.
Save parzibyte/438ba19c7e98bfa040cc6b969b9f08eb to your computer and use it in GitHub Desktop.
// 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