Bonjour,

Je suis entrain d'écrire un programme qui permet de définir une structure.
Cette structure sera par la suite utilisé pour lire un fichier de donnée ( 4 colonne et 1000 lignes). Par la suite je veux allouer ces données en mémoire pour y travailler par la suite.

le programme est le suivant:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <malloc.h>
 
#define NUM_Element 1000
 
 
typedef struct
{
int Index;
int N;
float d;
float W;
}ind_struct;
 
ind_struct *ind_array;
 
 
int main(void)
{
FILE *ind_struct;
int i;
 
/*Read the input data file*/
ind_struct=fopen("Data.txt","r+");
if (ind_struct==NULL)
{
printf("the input data is not ready \n");
}
 
else
{
printf("the input data is ready \n");
 
ind_array = calloc(ind_array,NUM_Element,ind_struct);
if (ind_array== NULL) nomemory("input");
 
 
for (i=0; i<1000; i++) {
fscanf(ind_struct,"%e",&ind_array[i].d);
printf("%.3E \n",ind_array[i].d);
}
}
return 0;
}
 
 
/*====================================================================
Prints an error message and terminates the program
====================================================================*/
nomemory(string)
char *string;
{
printf("\nmalloc: out of memory making %s!!\n",string);
printf("\n Program is halting .....");
exit(-1);
}

Le code m'affiche un faux résultat. Quelqu’un peux m'aider à corriger ce programme?

Merci d'avance.