I have this up to now, the newfile function that gives the info to some global vars (parts[i], totalparts[i], filearr[i]), how can I add more values to an array? mmm maybe I can think of using a list, but how can I store the FILE * pointer in an array? does the FILE pointer stores the filepath inside?
Code:
void newfile() {
char filepath[64];
recv(*sock, filepath, sizeof(filepath), 0);
//add to an array or something
}
void recieve(int *sock) {
char buff[64];
recv(*sock, buff, sizeof(buff), 0);
if(fwrite(buff, sizeof(buff), 1, filearr[i]) == 0) {
printf("Error writting file");
break;
}
else {
parts[i]++;
if(parts[i] == totalparts[i]) {
fclose(filearr[i]);
}
}
}
long fsize(const char *const name)
{
struct stat stbuf;
if(stat(name, &stbuf) == -1)
return -1; // The file could not be accessed.
return stbuf.st_size;
}
void send(int *sock) {
char buff[64];
FILE *file;
char filepath[64];
st_size size;
int parts;
size = fsize(filepath);
parts = size/512;
if(parts == 0) {
parts=1;
}
scanf( "%s", filepath );
if((file=fopen(filepath,"rb"))) {
for(i=0;i<=partstosend;i++) {
fread(buff, sizeof(buff), 1, file);
send(*sock, buff, sizeof(buff), 0);
}
}
}