Thread: Trouble with FILE & allegro

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    4

    Trouble with FILE & allegro

    Hi, I'm using allegro to make my interface but, some FILE commands , (like "text_printf") aren't working...
    what should I do??

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Show an example of what you are trying to do and I will point you in the right direction.
    Woop?

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    4
    this is a part of the code (some parts are in portuguese 'cause I'm brazilian and this is an college exercise, )

    --
    Code:
    #include <allegro.h>
    #include "all_io.h"
    
    void init(), corpo(), deinit(), menu(), formcadastro(), formbusca(), data();
    
    FILE *listacheques;
    
    
    int main() {
       
       if (inicia()) {
          
          corpo();
       
       } else {
          finaliza();
          return -1;
       } // fim do if
        
        finaliza();
        return 0;
    } END_OF_MAIN();
    
    void corpo() {
    
       /* Inicia o arquivo */
       if ((listacheques = fopen("reports/listchq.dll", "a+")) == NULL ){ 
          printf("\nError Code = x01\n");
          printf("Não foi possível acessar o arquivo.\n");
          getchar();
          exit(1); 
       }
       
       janela = create_bitmap(800,600);
       tela = load_bitmap("imagens/back.bmp",ptt);
       calendario = load_bitmap("imagens/data.bmp", ptt);
       menu1_on = load_bitmap("imagens/cadastrar_on.bmp", ptt);
       menu1_off = load_bitmap("imagens/cadastrar_off.bmp", ptt);
       menu2_on = load_bitmap("imagens/busca_on.bmp", ptt);
       menu2_off = load_bitmap("imagens/busca_off.bmp", ptt);
       menu3_on = load_bitmap("imagens/fechar_on.bmp", ptt);
       menu3_off = load_bitmap("imagens/fechar_off.bmp", ptt);
       botoes = load_sample("sons/sobt.wav");
       
       draw_sprite(janela, tela, 0, 0);
         
       text_mode(-1);
       set_window_title("Check Manager");
       prepara(1,8);
       
       cria_botao(212, 510, 160, 20, "Gravar Registro", 1);  
       
       cria_cxtexto(300, 205, 100, 20, 1, 1, 65535);
       cria_cxtexto(300, 240, 100, 20, 1, 1, 65535);
       cria_cxtexto(300, 275, 100, 20, 1, 1, 65535);
       cria_cxtexto(270, 310, 150, 20, 1, 1, 65535);
       cria_cxtexto(250, 345, 250, 20, 1, 1, 65535);
       cria_cxtexto(270, 380, 200, 20, 1, 1, 65535);
       cria_cxtexto(270, 415, 200, 20, 1, 1, 65535);
       cria_cxtexto(270, 450, 200, 20, 1, 1, 65535);
        
       while (!key[KEY_ESC]) {
    
          acompanha_mouse();
          show_mouse(tela);
          data();
       
       switch (botao_clique) {                            
          case 1:
             botao_clique = 0;
             
             fprintf(listacheques,"\n", cx_texto[0].texto);
             fprintf(listacheques,"DataRec:%s\n", cx_texto[0].texto);
             fprintf(listacheques,"NunChe:%s\n", cx_texto[1].texto);
             fprintf(listacheques,"NunBan:%s\n", cx_texto[2].texto);
             fprintf(listacheques,"Cidade:%s\n", cx_texto[3].texto);
             fprintf(listacheques,"Emitente:%s\n", cx_texto[4].texto);
             fprintf(listacheques,"Responsavel:%s\n", cx_texto[5].texto);
             fprintf(listacheques,"ValorChe:%s\n", cx_texto[6].texto);
             fprintf(listacheques,"DataVen:%s\n", cx_texto[7].texto);
             fprintf(listacheques,"-----------------------------");
             
             fclose(listacheques);
             allegro_message("Registro salvo com sucesso.");
             break;           
        } // fim do switch
    
         menu(); 
    
       } // fim do while
    
    } END_OF_FUNCTION(corpo);
    
    
    
    void init() {
    
    	int depth, res;
    	
        allegro_init();
    	set_color_depth(16);
    	res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0);
    
    	if (res != 0) {
    		allegro_message(allegro_error);
    		exit(-1);
    	}
    
    	install_keyboard();
    	install_mouse();
    
    } END_OF_FUNCTION(init);
    
    
    
    void deinit() {
        
        allegro_exit();
        clear_keybuf();
        exit(-1);
    
    } END_OF_FUNCTION(deinit);
    
    
    
    void menu() {
    
       /* Exibe as opções 'NOVO CHEQUE' do local 'MENU' */
       blit(menu1_off, tela, 0, 0, 643, 470, 85, 15);    
       if(mouse_x >= 643 && mouse_x <= 728 && mouse_y >= 470 && mouse_y <= 485) {
          blit(menu1_on, tela, 0, 0, 643, 470, 85, 15);
          /* Verifica se foi clicado e chama a função correspondente */
          if(mouse_b & 1) {
            play_sample(botoes, 180, 128, 1000, 0);
             formcadastro();
          } //fim do if
       } // fim do if
                 
       /* Exibe as opções 'BUSCA' do local 'MENU' */
       blit(menu2_off, tela, 0, 0, 643, 485, 85, 15);    
       if(mouse_x >= 643 && mouse_x <= 728 && mouse_y >= 485 && mouse_y <= 500) {
          blit(menu2_on, tela, 0, 0, 643, 485, 85, 15);
          /* Verifica se foi clicado e chama a função correspondente */
          if(mouse_b & 1) {
             play_sample(botoes, 180, 128, 1000, 0);
             formbusca();
          } //fim do if
       } // fim do if
    
       /* Exibe as opções 'FECHAR JANELA' do local 'MENU' */
       blit(menu3_off, tela, 0, 0, 643, 502, 85, 15);    
       if(mouse_x >= 643 && mouse_x <= 728 && mouse_y >= 502 && mouse_y <= 518) { 
       blit(menu3_on, tela, 0, 0, 643, 502, 85, 15);
       /* Verifica se foi clicado e chama a função correspondente */
          if(mouse_b & 1) {
          exit(-1);
          } //fim do if
       } // fim do if
    
    } END_OF_FUNCTION(menu);
    
    
    
    void formcadastro() {
       
       draw_sprite(janela, tela, 0, 0);
       
       textout(tela, font, "Data de recebimento:",160, 156, makecol(255,255,255));
       textout(tela, font, "(dd/mm/aaaa)",420, 156, makecol(255,255,255));
       textout(tela, font, "Numero do cheque:",185, 181, makecol(255,255,255));
       textout(tela, font, "Numero do banco:",193, 206, makecol(255,255,255));
       textout(tela, font, "Cidade:",235, 231, makecol(255,255,255));
       textout(tela, font, "Emitente:",162, 351, makecol(255,255,255));
       textout(tela, font, "Responsavel:",168, 386, makecol(255,255,255));
       textout(tela, font, "Valor do cheque:",136, 421, makecol(255,255,255));
       textout(tela, font, "Data de vencimento:",112, 456, makecol(255,255,255));    
    
       desenha_botoes();
       desenha_cxtexto();
       draw_sprite(screen, tela, 0, 0);
    
    } END_OF_FUNCTION(formcadastro);
    
    
    
    void formbusca() {
       
       readkey();
       
    } END_OF_FUNCTION(formbusca);
    
    
    
    void data() {
       
       draw_sprite(tela, calendario, 700, 85);
       draw_sprite(screen, tela, 0, 0);
    
       /* Pega a data do sistema */
       time_t time_info;
       time(&time_info);
       
       struct tm *time_info_struct = localtime(&time_info);
          int ano = time_info_struct->tm_year + 1900;
          int dia = time_info_struct->tm_mday;
          int mes = time_info_struct->tm_mon + 1;
    
       /* Imprime o dia (Formato 0d ou dd) */
       if (dia < 10){
          textprintf(calendario, font, 0, 6, makecol(255,255,255), "0%d/",dia);
       } else {
            textprintf(calendario, font, 0, 6, makecol(255,255,255), "%d/",dia);
       } // fim do if
    
       /* Imprime o mês (Formato 0m ou mm) */
       if (mes < 10){
          textprintf(calendario, font, 24, 6, makecol(255,255,255), "0%d/",mes);
       } else {
          textprintf(calendario, font, 24, 6, makecol(255,255,255), "%d/",mes);
       } // fim do if
    
       /* Imprime o ano */
       textprintf(calendario, font, 49, 6, makecol(255,255,255), "%d",ano);
    
       /* Mostra na tela as funções de cima */
       draw_sprite(tela, calendario, 700, 85);
       draw_sprite(screen, tela, 0, 0);
    } END_OF_FUNCTION(data);
    --

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  2. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  5. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM