| | |
Multiple inputs for char / arrays of arrays
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2005
Posts: 2
Reputation:
Solved Threads: 0
I am using VC++6.0
I am attempting to implement the TEA for a Oracle server. I am plannng to write the algorithm in C++(C), then add it to a shared library.
I am new with C++ and I am having some difficlulty, mainly in two basic areas:
1. I want to extract, for test purposes from the keyborad the key and message. Howeve, I cout the prompt for key, then cout the prompt for message. I cin.getline(k,15,'\n') for the key and the same for the message. If I go over the key specified limit I am not able to enter the message at all. When I cout the key and message the key is returned fine 16 chars etc, but the message isn't even prompted to enter. I see what's going wrong, but I really need to know how to resolve it.
2. The second issue folows on from this. I want to accept an inputted message and key. I use an array to take the inputs. I then want to use the 32bit (4byte) pieces of the message and key for binary operations. So I want to take the eg 16 character key, and use the first 4 chars, then 2nd 4, etc..etc.. How do I do this...??? Also with the message???
I am attempting to implement the TEA for a Oracle server. I am plannng to write the algorithm in C++(C), then add it to a shared library.
I am new with C++ and I am having some difficlulty, mainly in two basic areas:
1. I want to extract, for test purposes from the keyborad the key and message. Howeve, I cout the prompt for key, then cout the prompt for message. I cin.getline(k,15,'\n') for the key and the same for the message. If I go over the key specified limit I am not able to enter the message at all. When I cout the key and message the key is returned fine 16 chars etc, but the message isn't even prompted to enter. I see what's going wrong, but I really need to know how to resolve it.
2. The second issue folows on from this. I want to accept an inputted message and key. I use an array to take the inputs. I then want to use the 32bit (4byte) pieces of the message and key for binary operations. So I want to take the eg 16 character key, and use the first 4 chars, then 2nd 4, etc..etc.. How do I do this...??? Also with the message???
Your compiler is new enough, you should be using the string class rather than C-style strings. That would sidestep the problem you're having entirely:
The problem you're having is identical to what you would see in C with fgets. The first call reads n-1 characters and returns without extracting a newline character, the second call read everything that was left. The effect is that it looks like the second call for input is skipped. The solution is also identical to what you would do in C (assuming you don't want to use the string class).
>use the 32bit (4byte) pieces of the message and key for binary operations
What binary operations are you planning on using?
C++ Syntax (Toggle Plain Text)
#include <string> std::string key; std::string msg; std::cout<<"Enter the key: "; if (!std::getline(std::cin, key)) { // Handle input error } std::cout<<"Enter the message: "; if (!std::getline(std::cin, msg)) { // Handle the error }
>use the 32bit (4byte) pieces of the message and key for binary operations
What binary operations are you planning on using?
I'm here to prove you wrong.
•
•
Join Date: Mar 2005
Posts: 2
Reputation:
Solved Threads: 0
I understand what you have told me, and thnks.
However, I am still having the same problem. I want the program to take the first 16 chars of anything entered as key. After hitting return(newline) I then want the cin buffer to be empty, ready to take an upto 1024 chars for the message. I want these two inputs to be divided into 32-bit (4 byte) chunks, ready for binary operations, such as Xor, Adding. Then at the end I'll en up with two 32bit pieces, which is effectively the envrypted mesage. Another issue I am having is how do I return this two piece message back as a single concatenated string.
However, I am still having the same problem. I want the program to take the first 16 chars of anything entered as key. After hitting return(newline) I then want the cin buffer to be empty, ready to take an upto 1024 chars for the message. I want these two inputs to be divided into 32-bit (4 byte) chunks, ready for binary operations, such as Xor, Adding. Then at the end I'll en up with two 32bit pieces, which is effectively the envrypted mesage. Another issue I am having is how do I return this two piece message back as a single concatenated string.
![]() |
Similar Threads
- Errors with Char arrays (C++)
- Help with char arrays (C)
- Multiple inputs? (C++)
- Confused about use * in declaring char arrays (C++)
Other Threads in the C++ Forum
- Previous Thread: PLease can somebody help
- Next Thread: HELP!!!.. (graphics.h)
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator getline graph homeworkhelper iamthwee ifstream image input int integer java lib list loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings struct template text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






