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
|
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define TEMP 60
//-----------DEBUT-PROGRAMME------------//
void main (void)
{
//Declaration(s) de la(des) variable(s)
char daterecherche[6], nomfic_srcPCA[TEMP];
FILE *stream;
int list[50];
int i, numread, numwritten;
//Demande du parametre "daterecherche"
printf("Veuillez saisir la date de la recherche pour les prelevement\n");
fgets(daterecherche, 7, stdin); //date au format JJMMAA !
strncpy (nomfic_srcPCA, "Fichier_cherche-", TEMP);
strncat (nomfic_srcPCA, daterecherche, TEMP);
if(nomfic_srcPCA)
{
printf("Fichier trouve\n");
//ecriture dans le nouveau fichier
if( (stream = fopen("Nouveau_Fichier.txt", "wb")) != NULL)
{
//JE VEUX QUE MON ECRITURE DANS list
//SOIT AU FORMAT TEXTE => en ASCII
for (i=0; i<50; i++)
{
list[i] = (char)(list[i]);
}
//Dans fwrite je ne met que 50 juste pour mon essai
numwritten = fwrite (list, sizeof(char), 50, stream);
printf("Wrote %d items\n", numwritten);
fclose(stream);
}
else
{
printf("Problem opening the file\n");
}
//affichage du contenu à l’ecran
if( (stream = fopen("nomfic_srcPCA", "rb")) != NULL)
{
numread = fread(list, sizeof(char), 50, stream);
printf("Number of items read = %d\n", numread);
printf("Contents of buffer = %.50s\n", list);
fclose(stream);
}
else
{
printf("File could not be opened\n");
}
}
else
{
printf("Erreur fichier\n");
}
}
//-----------FIN-PROGRAMME------------// |
Partager