Not able to send many images to server using vector<T> in C++ -


i changing signature of function having default argument char* vector in c++. role of function default argument char* take out image name of image file, read image file , send server. function capable of sending 1 image file. so, went vector send multiple images @ once. but, somewhere missing on not able find out. if can please help.

function default parameter of char*:

void filesend(char *fpath) {     // extract filename given path.     char filename[50];     int = strlen(fpath);     (; > 0; i--)     {         if (fpath[i - 1] == '\\')             break;     }     (int j = 0; <= (int)strlen(fpath); i++)     {         filename[j++] = fpath[i];     }      ifstream myfile(fpath, ios::in | ios::binary | ios::ate);     int size = (int)myfile.tellg();     myfile.close();      char filesize[10]; itoa(size, filesize, 10);     send(sock, filename, strlen(filename), 0);     char rec[32] = "";      recv(sock, rec, 32, 0);      send(sock, filesize, strlen(filesize), 0);     recv(sock, rec, 32, 0);      file *fr = fopen(fpath, "rb");      while (size > 0)     {         char buffer[1030];          if (size >= 1024)         {             fread(buffer, 1024, 1, fr);             send(sock, buffer, 1024, 0);             recv(sock, rec, 32, 0);         }         else         {             fread(buffer, size, 1, fr);             buffer[size] = '\0';             send(sock, buffer, size, 0);             recv(sock, rec, 32, 0);         }         size -= 1024;     }     fclose(fr); } 

function default parameter of vector:

void filesend(vector<string> fnames)     {         char *filename;         (int k = 0; k < fnames.size(); k++)         {             int = fnames[k].length;              (; > 0; i--)             {                 if (fnames[k][i - 1] == '\\')                     break;             }             (int j = 0; <= fnames[k].length(); i++)             {                 filename[j++] = fnames[k][i];             }              ifstream myfile(fnames[k], ios::in | ios::binary | ios::ate);             int size = (int)myfile.tellg();             myfile.close();              char filesize[10]; itoa(size, filesize, 10);             send(sock, filename, strlen(filename), 0);             char rec[32] = "";             recv(sock, rec, 32, 0);              send(sock, filesize, strlen(filesize), 0);             recv(sock, rec, 32, 0);              file *fr = fopen(fnames[k], "rb");              while (size > 0)             {                 char buffer[1030];                  if (size >= 1024)                 {                     fread(buffer, 1024, 1, fr);                     send(sock, buffer, 1024, 0);                     recv(sock, rec, 32, 0);                 }                 else                 {                     fread(buffer, size, 1, fr);                     buffer[size] = '\0';                     send(sock, buffer, size, 0);                     recv(sock, rec, 32, 0);                 }                 size -= 1024;             }             fclose(fr);         }     } 


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -