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
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
typedef struct
{
char *delim;
unsigned int lignes;
unsigned int colonnes;
char **table;
}CSV;
int suppr_csv(CSV * csv) {
if (csv == NULL) { return 0; }
if (csv->table != NULL) { free(csv->table); }
if (csv->delim != NULL) { free(csv->delim); }
free(csv);
return 0;
}
CSV* csv_esp_mem(unsigned int colonnes, unsigned int lignes)
{
CSV*csv;
csv=malloc(sizeof(CSV));
csv->lignes=lignes;
csv->colonnes=colonnes;
csv->delim=strdup(";");
csv->table=malloc(sizeof(char*)*colonnes*lignes);
if(csv->table==NULL){goto erreur;}
memset(csv->table,0,sizeof(char *)*colonnes*lignes);
return csv;
erreur:
suppr_csv(csv);
return NULL;
}
int csv_ecriture_seule(CSV* csv,char *Nom_Fichier)
{
FILE*fichier;
fichier=fopen(Nom_Fichier,"r");
if (fichier==NULL){goto erreur;}
return 0;
erreur:
fclose(fichier);
printf("Impossible a ouvrir");
return -1;
}
void ecrire_in_fichier_CSV(FILE* fichier,int donnees)
{
fprintf(fichier,"%d",donnees);
fclose(fichier);
}
int main()
{
CSV *nouveaucsv;
nouveaucsv=csv_esp_mem(20,100);
char fichier_name="rapport_1.csv";
csv_ecriture_seule(nouveaucsv,fichier_name);
int donnees;
printf("entrez donnees:\n");
scanf("%d",&donnees);
ecrire_in_fichier_CSV(fichier,donnees);
return 0;
} |
Partager