void leer(struct estudiante *p)
{
FILE *ptr;
char temp[20],c;
int ctr=0,nc=0,aux=0;
if ((ptr= fopen("estudiante.txt","r+"))==NULL)
cout<<"No se puede abrir el archivo"<<endl;
else
{
p->cima=0;
while((c=getc(ptr))!=EOF) // el getc es para leer caracter por caracter
{
if(c!=9 && c!='n') // busca fin de linea o tab
{
temp[aux]=c; // realiza la captura de los caracteres e incrementa
aux++;
}
if(c==9)
{
if(ctr==0) strcpy(p->nombre[p->cima],temp); // copia el contenido de temp (todos los valores de c) a depor.nombre
if(ctr==1) p->codigo[p->cima]=atoi(temp); // conversion de char a int "toi"
if(ctr==2) strcpy(p->sexo[p->cima],temp);
if(ctr==3) strcpy(p->ciudad[p->cima],temp);
//if(ctr==4)
strcpy(temp," "); // como borrar el contenido de una variable char?
aux=0;
ctr++;
}
if(c=='n')
{
p->promedio[p->cima]=atoi(temp);
p->cima++;
ctr=0;
strcpy(temp," ");
}
}
}
fclose(ptr);
}