Ir para conteúdo
Fórum Script Brasil

fesoalll

Membros
  • Total de itens

    2
  • Registro em

  • Última visita

Posts postados por fesoalll

  1. O erro esta no modo como você retornou os dados da função.

    #include <stdio.h>
    #include <stdlib.h>

    int menu (char sinal);
    int valores (int num1, int num2);
    char ans;

    int main ()
    {big:
        char operador;
        printf("\t\também Vindo a Calculadora\n");
        printf("Digite um dos sinais matematicos a seguir: '+','-','*','/','%'\n");
        scanf("%c",&operador);
        menu(operador);
    printf("\n Para realizar outra operaçao tecle Enter.\n Para finalizar tecle q >> enter.");
    fflush(stdin);
    scanf("%c",&ans);

    if(ans!='q')goto big;
    else goto end;

    end:
    return 0;
    }
    int valores1(int num1)
    {   printf("=---------------------------------------------------------------=\n");
        printf("Digite o Valor 1:\n");
        scanf("%i", &num1);
        return num1;
    }
    int valores2(int num2)
    {
     printf("Digite o Valor 2:\n");
        scanf("%i", &num2);
    return num2;
    }

    int menu(char sinal)
    {
        int operando1,
            operando2;
        switch(sinal)
        {
            case '+':
            {
                operando1=valores1(operando1);
                operando2=valores2(operando2);
                
                printf("%d%c%d=%d", operando1, sinal, operando2, operando1 + operando2);
                break;
            }
            case '-':
            {
                operando1=valores1(operando1);
                operando2=valores2(operando2);
                printf("%d%c%d=%d", operando1, sinal, operando2, operando1 - operando2);
                break;
            }
            case '*':
            {
                operando1=valores1(operando1);
                operando2=valores2(operando2);
                printf("%d%c%d=%d", operando1, sinal, operando2, operando1 * operando2);
                break;
            }
            case '/':
            {
                operando1=valores1(operando1);
                operando2=valores2(operando2);
                printf("%d%c%d=%d", operando1, sinal, operando2, operando1 / operando2);
                break;
            }
            case '%':
            {
                operando1=valores1(operando1);
                operando2=valores2(operando2);
                printf("%d%c%d=%d", operando1, sinal, operando2, operando1 % operando2);
                break;
            }
            default:
            {
                printf("Operador não reconhecido.\n");
            }
        }
    }

     

  2. Preciso de uma ajuda com esse codigo.

    Toda vez que a função screen() é chamada a memoria alocada não é liberada, fazendo aumentar o uso da memoria RAM até travar o pc.

    Como faço pra liberar essa memoria , segue o codigo:

    #include <iostream>
    #ifdef WIN32
    #include <windows.h>
    #else
    #include <unistd.h>
    #endif // win32

    using namespace std;
    void sleepcp(int milliseconds);
    char filename[64];
    FILE* f;

    void screen(char* fileName)
    {
        HWND window = GetDesktopWindow();
        HDC _dc = GetWindowDC(window);
        HDC dc = CreateCompatibleDC(0);
        
        RECT re;
        GetWindowRect(window, &re);
        int w = re.right,
            h = re.bottom;
        void* buf = malloc(w*h*4);
        
        HBITMAP bm = CreateCompatibleBitmap(_dc, w, h);
        SelectObject(dc, bm);
        
        StretchBlt(dc, 0, 0, w, h, _dc, 0, 0, w, h, SRCCOPY);
        
        void* f =CreateFile(fileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
        
        GetObject(bm, 84, buf);
        
        tagBITMAPINFO bi;
        bi.bmiHeader.biSize = sizeof(bi.bmiHeader);
        bi.bmiHeader.biWidth = w;
        bi.bmiHeader.biHeight = h;
        bi.bmiHeader.biPlanes = 1;
        bi.bmiHeader.biBitCount = 32;
        bi.bmiHeader.biCompression = 0;
        bi.bmiHeader.biSizeImage = 0;
        
        CreateDIBSection(dc, &bi, DIB_RGB_COLORS, &buf, 0, 0);
        GetDIBits(dc, bm, 0, h, buf, &bi, DIB_RGB_COLORS);
            
        BITMAPFILEHEADER bif;
        bif.bfType = MAKEWORD('B','M');
        bif.bfSize = w*h*4+54;
        bif.bfOffBits = 54;

        BITMAPINFOHEADER bii;
        bii.biSize = 40;
        bii.biWidth = w;
        bii.biHeight = h;
        bii.biPlanes = 1;
        bii.biBitCount = 32;
        bii.biCompression = 0;
        bii.biSizeImage = w*h*4;
        
        DWORD r;
        WriteFile(f, &bif, sizeof(bif), &r, NULL);
        WriteFile(f, &bii, sizeof(bii), &r, NULL);
        WriteFile(f, buf, w*h*4, &r, NULL);
        buf=NULL;
        
        free(buf);
        CloseHandle(window);
        CloseHandle(f);
        DeleteDC(_dc);
        DeleteDC(dc);
    }

    void sleepcp(int milliseconds) // cross-platform sleep function
    {
        #ifdef WIN32
        Sleep(milliseconds);
        #else
        usleep(milliseconds * 1000);
        #endif // win32
    }
    int main()
    {
        int A=0;
        char img[30];
    for(;;)
    {

      sprintf(img,"image%.3i.bmp",A);
      screen(img);
      printf("Imagem%.3i.bmp foi salva !\n",A);
    sleepcp(8000);
    A++;
    }
    return 0;
    }

     

    ATT.

×
×
  • Criar Novo...