#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct pila{
int clave;
char nombre[50];
float salario;
struct pila *psig;
}pila;
pila *pmaestro;
pila *NuevoElem();
void push(int clave,char nombre[],float salario);
void imprimir(pila *);
int main()
{
char nmbre[50];
int clve;
float slrio;
FILE *f1;
f1=fopen("listas.txt","r");
if(f1!=NULL){
// ********
while(!feof(f1)){
fscanf(f1,"%d,%s,%f",&clve,nmbre,&slrio);
push(clve,nmbre,slrio);
}
// ********
}else{
printf("Error de apertura");
}
imprimir(pmaestro);
fclose(f1);
return 0;
}
void push(int clave,char nombre[],float salario)
{ pila *q = NuevoElem();
q->psig = pmaestro;
q->clave = clave;
strcpy(q->nombre,nombre);
q->salario = salario;
pmaestro = q;
}
pila *NuevoElem()
{ pila *q = (pila *)malloc(sizeof(pila));
if (q==NULL) { printf("Falta memoria"); exit(0);}
return q;
}
void imprimir(pila *pmaestro)
{
while(pmaestro!=NULL)
{
printf("%d\t%s\t%f", pmaestro->clave,pmaestro->nombre,pmaestro->salario);
pmaestro = pmaestro->psig;
}
printf("\n");
}
This code must read a file that contains a series of keys, names and salaries. At the moment of wanting to read the file, for some reason the while is cycled and it does not advance from there. Why do you cycle?