Advertisement
Brandford

Prueba Archivos C

Aug 26th, 2013
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.65 KB | None | 0 0
  1. // Ingresar //
  2. //Declaración de función
  3. int ingresar_notas(WINDOW *barra_superior, WINDOW *barra_mensajes, int *p_marcar_item_seleccionado, FILE **p_arch1, char *p_ruta_arch1, struct notas *p_notas);
  4.  
  5. //Apertura del archivo
  6. *p_arch1= fopen(p_ruta_arch1, "a+b");
  7. if(*p_arch1 == NULL)
  8. {
  9.    curs_set(0);
  10.    noecho();
  11.    wprintw(barra_mensajes,"#Error: No se pudo leer el archivo");
  12.    wrefresh(barra_mensajes);
  13.    sleep(2);
  14.    werase(barra_mensajes);
  15.    wrefresh(barra_mensajes);
  16.    delwin(barra_superior);
  17.    delwin(barra_mensajes);
  18.    return(0);
  19. }
  20.  
  21. //Ingreso al archivo
  22. fseek(*p_arch1, 0, SEEK_END);
  23. fwrite(p_notas, sizeof(struct notas), 1, *p_arch1);
  24.  
  25. //Cerrar archivo
  26. if(fclose(*p_arch1) != 0)
  27. {
  28.    curs_set(0);
  29.    noecho();
  30.    wprintw(barra_mensajes,"#Error: No se pudo guardar el archivo");
  31.    wrefresh(barra_mensajes);
  32.    sleep(2);
  33.    werase(barra_mensajes);
  34.    wrefresh(barra_mensajes);
  35.    delwin(barra_superior);
  36.    delwin(barra_mensajes);
  37.    return(0);
  38. }
  39.  
  40.  
  41. // Buscar //
  42. //Declaración de función
  43. int busqueda_notas(WINDOW *barra_superior, WINDOW *barra_mensajes, int *p_marcar_item_seleccionado, FILE **p_arch1, char *p_ruta_arch1, struct notas *p_notas);
  44.  
  45. //Ejecución de busqueda
  46. fseek(*p_arch1, (atoi(selector_registro) - 1)*sizeof(struct notas), SEEK_SET);
  47. fread(p_notas, sizeof(struct notas), 1, *p_arch1);
  48.  
  49. //Cerrar archivo
  50. if(fclose(*p_arch1) != 0)
  51. {
  52.    curs_set(0);
  53.    noecho();
  54.    wprintw(barra_mensajes,"#Error: No se pudo guardar el archivo");
  55.    wrefresh(barra_mensajes);
  56.    sleep(2);
  57.    werase(barra_mensajes);
  58.    wrefresh(barra_mensajes);
  59.    delwin(barra_superior);
  60.    delwin(barra_mensajes);
  61.    return(0);
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement