So i have the following code:

//main program
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'};

    printf("Connection Successfully Established");
//class file

bool Class_Name::Send(int usize, int psize, char *username, char *password)
   itoa(usize,sendbuffer,16); // works fine
   itoa(psize,sendbuffer + 1,16); // works fine

   for(int i = 0; i< usize; i++)
       sendbuffer[i+2] = *(username + i); //works fine
   int x=2+usize;
   for(int H = 0; H<psize;H++)
	   sendbuffer[H+x] = *(password + H); // does not work

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

Basically the part where i put does not work doesn't input the information from the password const char * to the array and i'm not sure why it doesn't

Strings (if you do it the C way) should have a null character ('\0') to show where the end of the string is. Change your definitions to look like this:

char username[15] = {'r','g','f','i','r','e','f','l','y','2','4','\0'};
// or
char *username = "rgfirefly24"; //automatically adds the '\0'

I have changed it to char *username = "rgfirefly24" and char *password = "12345678" However the 12345678 still will not add to the char sendbufffer[1024].

changed my for loops to strcat and it works fine

This article has been dead for over six months. Start a new discussion instead.