Programación General > C/C++
manipulacion de archivos en c
(1/1)
kata_dav83:
Hola necesito urgente saber como guardo un arreglo de enteros en un archivo en c
el programa tiene como menu:
guardar archivo
mostrar datos archivo
eliminar archivo
y en internet no he podido encontrar nada util o comprensible
espero alguien me de alguna ayudita porfis!!! :oops:
m0skit0:
Cuatro palabros: fopen, fread, fwrite, y fclose :lol:
Busca sobre ello. Saludos.
kata_dav83:
gracias :D
SincodigosxD:
buenas soy nuevo en el foro y estudio programacion hace medio año y tambien tengo dudas con el uso de esas funciones, estoy haciendo un programita muy sencillo (ahora se los pego) pero necesito saber como hacer para guardar los datos y que cuando el programa se vuelva a abrir ya esten cargados
El programa pretende organizar gastos lo tengo por la mitad recien lo empece.. si alguien me puede ayudar le voy a agradecer
--- Código: C ---#include <stdio.h>#include <stdlib.h>#include <conio.h>#include<string.h> struct Gastos { char nombre[20]; float cantidad; int pos; };//declaracion de funcionesvoid menu ();void agregar(int* A, struct Gastos gastos[]);void mostrar(int* A, struct Gastos gastos []);void editar(int* A,struct Gastos gastos[]);void burbunum (int A,struct Gastos gastos[]);void burbupal(int A,struct Gastos gastos[]);//bloque principalint main (){ struct Gastos gastos[15]; int opc,a=1,flag=0,i=0;do{ menu(); scanf("%d",&opc); switch(opc){ case 1: fflush(stdin); system("cls"); agregar(&a,gastos); system("cls"); fflush(stdin); printf("Los datos guardados para la posicion %d fueron:nn" "%s $%.2f",gastos[a-1].pos, gastos[a-1].nombre , gastos[a-1].cantidad); getchar(); break; case 2: system("cls"); mostrar(&a,gastos); getch(); fflush(stdin); break; case 3: system("cls"); editar(&a,gastos); fflush(stdin); break; case 4: system("cls"); burbunum(a,gastos); printf(" NOMBRE GASTOSn"); printf(" ------ ------n"); for (i=1;i<a;i++){ printf(" %-15s $%-6.2f", gastos[i].nombre,gastos[i].cantidad); printf("n"); } getch(); break; case 5: system("cls"); burbupal(a,gastos); printf(" NOMBRE GASTOSn"); printf(" ------ ------n"); for (i=1;i<a;i++){ printf(" %-15s $%-6.2f", gastos[i].nombre,gastos[i].cantidad); printf("n"); } getch(); break; case 9: flag=1; break; }}while(flag==0);return 0;}//Desarrollo de funcionesvoid menu (){ system("cls"); printf("1-Agregarn"); printf("2-Mostrar datosn"); printf("3-Editar datosn"); printf("4-Ordenar por gastosn"); printf("5-Ordenar por nombren");}void agregar(int* A,struct Gastos gastos[]){ printf("Tipo de gasto: "); scanf("%s",&gastos[*A].nombre); printf ("nCantidad $: "); scanf("%f",&gastos[*A].cantidad); gastos[*A].pos=*A; *A+=1;}void mostrar (int* A, struct Gastos gastos []){ int i=1,w=1; printf("POS NOMBRE GASTOSn"); printf("--- ------ ------n"); for (i=1;i<*A;i+=1){ printf("%-5.2i %-15s $%-6.2f", w , gastos[i].nombre,gastos[i].cantidad); printf("n"); w++; } }void editar(int* A,struct Gastos gastos[]){ int OPC; mostrar(A,gastos); printf("nQue posicion desea editar?"); scanf("%i",&OPC); printf("Tipo de gasto: "); scanf("%s",&gastos[OPC].nombre); printf ("nCantidad $: "); scanf("%f",&gastos[OPC].cantidad);}void burbunum(int A,struct Gastos gastos[]){ int i=0,flag=0; struct Gastos aux; while (flag==0){ flag=1; for (i=1;i<A-1;i++){ if (gastos[i].cantidad>gastos[i+1].cantidad){ aux=gastos[i+1]; gastos[i+1]=gastos[i]; gastos[i]=aux; flag=0; } } } }void burbupal(int A,struct Gastos gastos[]){ int i=0,flag=0; struct Gastos aux; while (flag==0){ flag=1; for (i=1;i<A-1;i++){ if (strcmp(gastos[i].nombre,gastos[i+1].nombre)>0){ aux=gastos[i+1]; gastos[i+1]=gastos[i]; gastos[i]=aux; flag=0; } } } }
Navegación
Ir a la versión completa