1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
using namespace std;
int main()
{
FILE * output_file2=fopen ("D:/main/test1.txt" , "w" );
///
int i=0,w=320,H=280,j;
int size=w*H ;
double *xoff =new double[w*H];
double x=0;
ifstream fichier("test2.txt", ios::in); // open the file
if(fichier)
{
string ligne;
while(getline(fichier, ligne,' '))
{
x=atof(ligne.c_str());//conversion from string-->double
xoff[i]=x;
// cout <<x << endl; // on l'affiche
// printf("xoff[%d]=%lf\n",i,xoff[i]);
i++;
}
}
else
cerr << "Impossible d'ouvrir le fichier !" << endl;
int dim_allouee=0;
double **gr=0;
gr = new double*[H];
for( dim_allouee=0; dim_allouee<H; dim_allouee++)
{
gr[ dim_allouee] = new double[w];
}
for(i=0;i<H;i++)
for(j=0;j<w;j++)
{
//printf("xoff[%d]=%lf\n",j,xoff[j]);
gr[i][j]=xoff[w*i+j];
}
for(i=0;i<H;i++)
{
for(j=0;j<w;j++)
{
fprintf(output_file2,"%.14lf ",gr[i][j]);
}
fprintf(output_file2,"\n");
}
return 0;
delete[]xoff;
for(i=0;i< dim_allouee;i++)
{
delete[] gr[i];
}
delete [] gr;
}
|