Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

About this user

1 total

Lectura de archivo secuencial en C

// Ejemplo de lectura de archivo secuencial

#include <stdio.h>

void main()
{
    FILE *ptr;
    char nombre[15],c;
    int ok, edad;

    ptr = fopen("datos.txt", "r");

    do
    {
						/* Obtiene datos del archivo*/
        ok = fscanf(ptr, "%d %s", &edad, nombre);
	   if (ok)
           printf("Edad: %d\n Nombre:%s\n", edad, nombre); /* despliega en pantalla */
	   else
	   printf("*****Error en la lecura");
    }
    while (!feof(ptr));            /* Se repite hasta encontrar EOF (ctrl + z) */

    fclose(ptr);
    printf("pulse una tecla para continuar");
    scanf("%c", &c);
}
1 total