adding const char * to char array

ok i'm adding 2 ints and 2 const char *'s to a char array. The two ints and the first const char * go just fine into the array, but the second const char * does not.
Here is the code:

1
2
3
4
5
6
7
8
(this is in main)
char username[15] = {'r','g','f','i','r','e','f','l','y','2','4'};
char password[9] = {'1','2','3','4','5','6','7','8'};

if(client.Send(15,9,username,password))
{
     printf("Connection Successfully Established");
}

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
(this part is in my class file)

bool Class_Name::Send(int usize, int psize, char *username, char *password)
{
   
   itoa(usize,sendbuffer,16);  // enters in the array just fine
   itoa(psize,sendbuffer + 1,16); // enters in the array just fine

   for(int i = 0; i< usize; i++)
   {
       sendbuffer[i+2] = *(username + i); // enters in the array just fine
   }
    
   int x=2+usize;
   for(int H = 0; H<psize;H++)
   {
       
	   sendbuffer[H+x] = *(password + H); //does not get put in the array at all
   }



    SentBytes = send(client_socket, sendbuffer, strlen(sendbuffer), 0);
    
    if (SentBytes == SOCKET_ERROR)
    {
        return false;
    }
    return true;
}

I'm not sure what i'm doing wrong when attempting to enter in the second const char *
Last edited on
Where is sendbuffer declared?
Last edited on
Topic archived. No new replies allowed.