Les dejo el codigo para que puedan verlo
Código
#include <stdio.h> #include <conio.h> #include <stdlib.h> #define DIR "productos.txt" typedef struct{int cod_art; float peso; char nombre[15], desc[120];}t_producto; int main() { t_producto producto; FILE *pf; char opc; if((pf=fopen(DIR,"w"))==NULL) { printf("\nEl Archivo no puede ser abierto"); exit(1); } printf("Ingresar un Articulo nuevo (s/n)?: "); opc=getche(); while(opc=='s') { printf("\nIngresar Codigo del Articulo: "); fflush(stdin); scanf("%d", &producto.cod_art); printf("Ingresar Nombre del Articulo: "); fflush(stdin); gets(producto.nombre); printf("Ingresar Descripcion del Articulo: "); fflush(stdin); gets(producto.desc); printf("Ingresar Peso del Articulo: "); scanf("%f", &producto.peso); fwrite(&producto,sizeof(producto),1,pf); printf("\nIngresar un Articulo nuevo (s/n)?: "); opc=getche(); } fclose(pf); return (1); }