| 12
 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
 
 |  
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
    char num;
    int flag;
}shiki;
 
shiki **load_dati(char *, int *);
 
int main()
{
    shiki **t;
    int n;
    t=load_dati("iniziale.txt",&n);
 
    printf("Hello world!\n");
    return 0;
}
 
shiki ** load_dati(char *filename, int *n)
{
    shiki **t;
    int num,i,j=0;
    char c1;
    FILE *f;
    if((f=fopen("iniziale.txt","r"))==NULL)
    {
        printf("errore apertura");
        exit(EXIT_FAILURE);
    }
    fscanf(f,"%d",&num);
    *n=num;
    t = (shiki **) malloc ((2*num-1) * sizeof (shiki *));
    if (t == NULL)
    {
        printf("Memory allocation error.\n");
        exit(EXIT_FAILURE);
    }
 
    for (i=0; i < 2*num-1; i++)
    {
        t[i] = (shiki *) malloc ((2*num-1) * sizeof (shiki));
        if (t[i] == NULL)
        {
            printf("Memory allocation error.\n");
            exit(EXIT_FAILURE);
        }
    }
    i=0;
    while(fscanf(f,"%c",&c1)!=EOF)
    {
        if(c1!='\n' && c1!=' ')
        {
            t[i][j].num=c1;
            j++;
        }
        if(c1=='\n')
        {
            j=0;
            i++;
        }
 
    }
    return t;
 
} | 
Partager