944,027 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 7682
  • C++ RSS
Mar 8th, 2005
0

Multiple inputs for char / arrays of arrays

Expand Post »
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???
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Almost a GURU is offline Offline
2 posts
since Mar 2005
Mar 8th, 2005
0

Re: Multiple inputs for char / arrays of arrays

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:
C++ Syntax (Toggle Plain Text)
  1. #include <string>
  2.  
  3. std::string key;
  4. std::string msg;
  5.  
  6. std::cout<<"Enter the key: ";
  7. if (!std::getline(std::cin, key)) {
  8. // Handle input error
  9. }
  10.  
  11. std::cout<<"Enter the message: ";
  12. if (!std::getline(std::cin, msg)) {
  13. // Handle the error
  14. }
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?
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Mar 9th, 2005
0

Re: Multiple inputs for char / arrays of arrays

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Almost a GURU is offline Offline
2 posts
since Mar 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: PLease can somebody help
Next Thread in C++ Forum Timeline: HELP!!!.. (graphics.h)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC