| | |
unable to add char array of numbers to another char array
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2009
Posts: 3
Reputation:
Solved Threads: 0
So i have the following code:
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
C++ Syntax (Toggle Plain Text)
//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'}; if(client.Send(15,9,username,password)) { printf("Connection Successfully Established"); }
C++ Syntax (Toggle Plain Text)
//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
Last edited by rgfirefly24; Mar 3rd, 2009 at 8:39 pm.
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:
C++ Syntax (Toggle Plain Text)
char username[15] = {'r','g','f','i','r','e','f','l','y','2','4','\0'}; // or char *username = "rgfirefly24"; //automatically adds the '\0'
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: Load a Dynamic Link Library (DLL)
- Next Thread: Beginner and I would love help :) date validation
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph gui homeworkhelp iamthwee ifstream image input int java lib library list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets





