Skip to content

Instantly share code, notes, and snippets.

@parzibyte

parzibyte/leer.c Secret

Created October 29, 2020 23:57
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/64404cf5d882537836275d366d8f16bb to your computer and use it in GitHub Desktop.
Save parzibyte/64404cf5d882537836275d366d8f16bb to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
#define NOMBRE_ARCHIVO "archivo.txt"
#define LONGITUD_MAXIMA_CADENA 1000
int main(void)
{
FILE *archivo = fopen(NOMBRE_ARCHIVO, "r"); // Modo lectura
char bufer[LONGITUD_MAXIMA_CADENA]; // Aquí vamos a ir almacenando cada línea
while (fgets(bufer, LONGITUD_MAXIMA_CADENA, archivo))
{
// Aquí, justo ahora, tenemos ya la línea. Le vamos a remover el salto
strtok(bufer, "\n");
// La imprimimos, pero realmente podríamos hacer cualquier otra cosa
printf("La línea es: '%s'\n", bufer);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment