int main
{
clrscr();
char c = 0;
while ( c != '\n' )
{
cin.get(c);
cout << "-";
cout<<c; //----------display the entered character..
}
cout << endl;
getch();
return 0;
}
actually your string is entered successfully but you not display it back again....
nd in ur output ur "hello world" is that wat u write ...and "-" is what u dislpay in output.. cout<<"-"; :p
#include <iostream.h>
#include<conio.h>
void main()
{
char c;
while ( c != '\t') //----press tab key to exit
{
c=getche();
cout<<"-";
}
}
I tried hard to it....bt seriously i found this problem...very complicated to me....at the end i did this and get the result...but i em not satisfied....i ll' try it later dude oka....
"I am confused because cin.get() extracts a character from the stream without the user pressing the return key. "
I'm not sure if this is true. Seems like the compiler is executing the rest of the loop as soon as you press enter.
#include <iostream.h>
#include<conio.h>
int main()
{
char c='\0';
while ( c != '\r')
{
c=getche();
cout<<"-";
}
return 0;
}
finally got something for u... use carrige return to terminate the while...
nd getche as it does not hold the characters and does not require ENTER to execute,,,as in case of cin.get or getchar...
You seem to be confused as to how cin.get() works. It doesn't grab characters as the user types them. What cin.get() does is get the next character to be entered into the cin stream and store it in the specified variable. So what your code does is loop through every character the user enters, storing it in the "c" variable, and then printing a "-". What you need to do is change this line:
But he specifically wanted it to add a dash immediately after each character he types, AS he types...not to repeat what he typed with a dash after each letter.
@firedraco-
i usually work on windows....nd i use the traditional c compiler....may u r familiar with gcc linux compiler....... i don't think dat i should change my os for such things....it only matter the logic.....if u r programmer than u must knw dat syntax may differ bt logic...is always same in all languages....