By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,903 Members | 1,257 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,903 IT Pros & Developers. It's quick & easy.

char.getline

P: n/a
How can I "save" a char? Egg: I write a program that asks the name of
the user. Then I want to keep this name saved so the program can use it
later. BUT I can't save more than one char, so if the program asks the
name of the user and saves it, I can't save any other word to use
later, or I will lost the name....
this seems confusing, but anyway, does anyone know how to solve it?

(don't think i'm stupid i'm 13)

Oct 31 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Yusuke Urameshi wrote:
How can I "save" a char? Egg: I write a program that asks the name of
the user. Then I want to keep this name saved so the program can use it
later. BUT I can't save more than one char, so if the program asks the
name of the user and saves it, I can't save any other word to use
later, or I will lost the name....
this seems confusing, but anyway, does anyone know how to solve it?


Not without more information. How about you start by reading the FAQ:
http://www.parashift.com/c++-faq-lite/

Then, reread section 5.8 and post again.

Kristo

Oct 31 '05 #2

P: n/a
you have to set how long that char will be so it knows how many
characters it can hold

say the longest name would be like 50 characters long

char name[51];

you always add one to the end becuase your memory will give a endline
statement. if you didnt, it would cut off the last letter to add it.

try that and it will work.

Oct 31 '05 #3

P: n/a
Yusuke Urameshi wrote:
How can I "save" a char? Egg: I write a program that asks the name of
the user. Then I want to keep this name saved so the program can use it
later. BUT I can't save more than one char, so if the program asks the
name of the user and saves it, I can't save any other word to use
later, or I will lost the name....
this seems confusing, but anyway, does anyone know how to solve it?

(don't think i'm stupid i'm 13)

char's store single characters.
They aren't strings (multiple characters).
Find a C++ book and read about the standard "string" type.

You don't know enough about C++ yet to be screwing around
with pointers.
Nov 1 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.