Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created March 18, 2020 20:46
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/03557e78f7257aadb1831e9c00c1ce44 to your computer and use it in GitHub Desktop.
Save parzibyte/03557e78f7257aadb1831e9c00c1ce44 to your computer and use it in GitHub Desktop.
void cargarArchivoEnMemoria() {
FILE *archivoOriginal;
int tamanioBuffer = MAXIMA_LONGITUD_LINEA;
char linea[tamanioBuffer];
archivoOriginal = fopen(nombreArchivoOriginal, "r");
if (archivoOriginal == NULL) {
printf("Imposible leer el archivo %s", nombreArchivoOriginal);
exit(EXIT_FAILURE);
}
while (fgets(linea, tamanioBuffer, archivoOriginal)) {
size_t longitudLinea = strlen(linea);
// Checar si la línea no es un salto de línea vacío
if (longitudLinea > 1) {
// De la línea, removemos el salto de línea
strtok(linea, "\n");
agregarLineaALista(linea);
}
}
fclose(archivoOriginal);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment