reading a single character at a time

i am trying to make a program to encrypt a character string.for this i require the compiler to read a single character at a time,process it and go on for the next character and so on untill the user press the enter key...but i am not able to read a single character at a time and process it...
FOR eg:
if i declare something like what is given below

1
2
char h;
cin>>h;

thought the compiler will store only one character but the user is allowed to enter as many characters as he wants...this is what i dont want..following is my strategy
1
2
3
4
5
6
7
8
9
int i=0;
    char h=0,arr[100];
    while((int)h!=13)
    {
        cin>>h;
        cout<<"\b"<<"*";
        h=arr[i];
        i++;
    }

but this is definitely not working for the reason mentioned above....plz help me out with this....
Last edited on
Why don't you want to read the whole string first and process the encryption?

It goes as follows:
1
2
3
4
5
6
7
8
    char array[100];
    memset(array, 0, 100);

    cin >> array;

    cout << "original text: " << array << endl;
    cout << "encrypted text: "; // It is shifted by one character
    for (int i = 0; array[i] != 0 && i < 100; i++) cout << (char)(array[i] + 1) << " ";


But I suggest that you should use the c++ style string.
i dont want to make the user see what he is entering....sumthing like when you type your password.....plz help me out
closed account (zb0S216C)
Try this:
http://www.cplusplus.com/forum/general/3570/page1.html#msg15410

Wazzak
Or this: http://www.cplusplus.com/forum/general/47820/#msg259525
or _getch() (#include <conio.h> ).

Alas, Framework's post does what you want best... (I should read more carefully!).
Last edited on
Topic archived. No new replies allowed.