tengo un fichero txt organizado en columnas, la primera tiene un numero entero del 1 en adelante, la segunda tiene un nombre y la tercera un precio. El caso es que no soy capaz de cargar el fichero en mi programa.
#include<stdio.h>
#define CadNom 30
#define NumPro 100
struct carta
{
int CodProducto;
char nombre[CadNom];
float precio;
};
struct carta productos[NumPro];
void cargarCarta(FILE *f, struct carta productos[NumPro], int *tamanio);
void imprimirCarta(struct carta productos[NumPro], int tamanio);
main()
{
FILE *fich;
int tamanio;
fich
= fopen("carta.txt", "r");
if(fich == NULL) return -1;
cargarCarta(fich, productos, &tamanio);
imprimirCarta(productos, tamanio);
}
void cargarCarta(FILE *f, struct carta productos[NumPro], int *tamanio)
{
/* CARGA LA CARTA AL PROGRAMA */
int i=0;
while(fscanf(f
, "%d" "%s" "%f", &productos
[i
].
CodProducto, productos
[i
].
nombre, &productos
[i
].
precio) != EOF
) {
i++;
}
*tamanio = i;
}
void imprimirCarta(struct carta productos[NumPro], int tamanio)
{
/*SE IMPRIME LA CARTA*/
int i=0;
printf("Codigo del producto\tNombre\t\tProducto"); printf("\n el tamanio es %d", tamanio
); while (i < tamanio)
{
printf("%d\n", productos
[i
].
CodProducto); i++;
}
}
Mod: No escribir en mayúsculas