Multiple inputs for char / arrays of arrays

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2005
Posts: 2
Reputation: Almost a GURU is an unknown quantity at this point 
Solved Threads: 0
Almost a GURU Almost a GURU is offline Offline
Newbie Poster

Multiple inputs for char / arrays of arrays

 
0
  #1
Mar 8th, 2005
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???
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,789
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 746
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Multiple inputs for char / arrays of arrays

 
0
  #2
Mar 8th, 2005
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:
  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?
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 2
Reputation: Almost a GURU is an unknown quantity at this point 
Solved Threads: 0
Almost a GURU Almost a GURU is offline Offline
Newbie Poster

Re: Multiple inputs for char / arrays of arrays

 
0
  #3
Mar 9th, 2005
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC