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
| void Copy_NewMsg_In_File (Message *msg)
{
FILE *f = NULL;
FILE *fc = NULL;
long lSize;
size_t result;
char *MyPacket;
f = fopen("C:\\glomosim\\glomosim\\network\\DataPacket.txt", "wb");
if (f == NULL)
{
printf("Impossible d'ouvrir le fichier DataPacket.txt");
}
else
{
//fprintf(f, "%s", msg->packet);
fwrite (msg->packet , 1 , sizeof(msg->packet) , f );
printf("\n avant packet = %s\n", msg->packet);
main_LZW();
fc = fopen("C:\\glomosim\\glomosim\\network\\test.out", "rb");
if (fc == NULL)
{
printf("Impossible d'ouvrir le fichier test.out");
}
else
{
fseek (fc , 0 , SEEK_END);
lSize = ftell (fc);
rewind (fc);
MyPacket = (char*) malloc (sizeof(char)*lSize);
if (MyPacket == NULL) {fputs ("Memory error",stderr); exit (2);}
result = fread (MyPacket,1,lSize,fc);
if (result != lSize) {fputs ("Reading error",stderr); exit (3);}
//fgets(msg->packet, 10, fc);
fclose(fc);
}
fclose(f);
}//else
printf("\n MyPacket = %s\n", MyPacket); // On affiche la chaîne
} |
Partager