Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
781 B
6
Indexable
Never
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>


using namespace std;

float* alokuj(int size) {
    float *tab = new float[size+1];
    tab[0] = static_cast<float>(size);
    return tab+1;
}

void zapiszDoP(const char* Fname,float* &tab) {
    FILE* desp = nullptr;
    desp = fopen(Fname,"wb");
    if (desp != nullptr) {
  
  
    for (size_t i = 0; i < tab[-1]; i++)
    {
    fprintf(desp, "%f ", tab[i]);

    }
    fclose(desp);

    }
    
}

void dealokuj(float* &tab) {
    delete[] (tab-1);
    tab = nullptr;
}

int main()
{
    float *tab= alokuj(10);
  
     for (size_t i = 0; i < tab[-1]; i++)
     {
         tab[i] = static_cast<float>(i);
         cerr << tab[i] << " ";
     }
    zapiszDoP("tabfloat.txt", tab);
    dealokuj(tab);
    
}