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
|
#define SEPARATOR '|'
void receiveStructFile(SOCKET sock, structFile *file){
char buffer[BUFFER];
int bytesLus;
char *tmp;
char *debut;
char *fin;
int taille;
bytesLus=recv(sock,buffer,BUFFER,0);
printf("Client %d> ",sock);
write(1,&buffer,bytesLus);
printf("\n");
debut=buffer+2;
printf("%s\n",debut);
fin=(char *)strchr(debut,SEPARATOR);
taille=(fin-debut);
// printf("%s\n",fin);
tmp=(char *) malloc(taille*sizeof(char));
strncpy(tmp,debut,taille);
printf("%s\n",tmp);
debut=fin+1;
fin=(char *)strchr(debut,SEPARATOR);
taille=(fin-debut);
// printf("%s\n",fin);
tmp=(char *) realloc(tmp,taille*sizeof(char));
strncpy(tmp,debut,taille);
printf("%s\n",tmp);
debut=fin+1;
fin=(char *)strchr(debut,SEPARATOR);
taille=(fin-debut);
// printf("%s\n",fin);
tmp=(char *) realloc(tmp,taille*sizeof(char));
strncpy(tmp,debut,taille);
printf("%s\n",tmp);
free(tmp);
debut=fin+1;
// tmp=atoi(debut);
printf("%i\n",atoi(debut));
} |