Mail Archives: djgpp/1997/12/31/16:03:42
--- On 31 Dec 1997 18:00:48 GMT Erik <edroszcz AT algonet DOT se> wrote:
>#include <iostream.h>
>
>int main()
>{
>char txt;
>
>cout << "Print a string: " << endl;
>
>So far I´ve got variable of the type CHAR called "txt". In txt should that
>you write be stored.
>
>Then the program will ask me to write something.
>Here is my problem. How should I store that write in the variable "txt"?
When you input a string, you can't store it in a single char. You have to
make room for a whole STRING, i.e - an *array* of chars.
Try the following code:
-------------------------------------
char Txt[30+1];
/* Declares an array of 30 characters + a place for a special
terminator (called NULL terminator), which marks the end of the actual
string. 30 chars might be too little - modify it as needed. */
cout << "Print a string: " << endl;
cin >>Txt; /* Inputs a string and stores it in Txt */
cout<<Txt; /* Prints your string */
---------------------------------------------
Noam Rotem
John Bryce Training Centre
Tel Aviv, Israel.
03-7535803
=============================================
1. Take upon yourself an impossible mission.
2. Accomplish the mission.
3. Go back to step 1.
It's the only sane answer to modern life.
---
31/12/97
22:45:28
- Raw text -