| | |
Concatenate strings/chars in a loop.
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2009
Posts: 8
Reputation:
Solved Threads: 0
Hi there.
I have an encryption method which handles a string char by char and converts it to base 32, then adds it onto the result string. However, it seems to completely replace the result string instead of adding onto the end of it. My code:
charCodeAt simply gets the unicode number in int format of the character entered. Can anyone help out?
I have an encryption method which handles a string char by char and converts it to base 32, then adds it onto the result string. However, it seems to completely replace the result string instead of adding onto the end of it. My code:
C++ Syntax (Toggle Plain Text)
char *encrypt(std::string input, std::string key) { char* result; int lenIn = input.length(); int lenKey = key.length(); int i = 0; int numKey; while (i < lenIn) { numKey = charCodeAt(key, i % lenKey); long n = long(charCodeAt(input, i) + numKey); ltostr(n, base32, 32); if (i = 0) { //Cannot concatenate a blank char* it seems result = base32; } else { char* tempresult = result; sprintf(result,"%s%s",tempresult,base32); } i++; } return result; }
charCodeAt simply gets the unicode number in int format of the character entered. Can anyone help out?
![]() |
Similar Threads
- How to concatenate two strings without using strcat? (C)
- XSLT: Need to concatenate strings in loop and hold them for later use (XML, XSLT and XPATH)
- vector of strings to chars (C++)
- Help for comparing strings and copying strings please. (C++)
- concatenate strings to open files (C++)
- Concatenating strings declared in the form of pointers (char*) (C++)
- How to use a for loop to clear a 2d array (C++)
Other Threads in the C++ Forum
- Previous Thread: Using a loop to display the characters for ACSII codes? HELP!
- Next Thread: please help, winsock2 10061 error
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






