473,396 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

char.getline

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
3 2865
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
by: Tim Johansson | last post by:
I'm new to C++, and tried to start making a script that will shuffle an array. Can someone please tell me what's wrong? #include <iostream.h> #include <string.h> int main () {...
12
by: Francis Bell | last post by:
Hello, I've got a program that is reading in a data file of 25 lines. Here is an example of the first two lines: sp/spinnerbait/AAA Lures/Mad Phil/silver/bass/1/1 f/floating minnow/AAA...
2
by: jalkadir | last post by:
I am trying to get character string from the user, to do that I use getline(char_type*, streamsize), but I get a segmentation fault??!! Can anyone give me a hand, what am I doing wrong? --snip...
3
by: gordy | last post by:
Newbie question, please by gentle. I'm trying to read in a text file containing the days of the week, one on each line. Each line should be pointed to by an array of pointers to char but I'm...
7
by: GRoll35 | last post by:
This is 1 source page of a project im working on. i just have this one error. i'll show the error then show the code.. i'll point out the line that it doesn't like. if anyone has any ideas or...
12
by: GRoll35 | last post by:
I get 4 of those errors. in the same spot. I'll show my parent class, child class, and my driver. All that is suppose to happen is the user enters data and it uses parent/child class to display...
4
by: sk | last post by:
I'm trying to write a little function that acts very similar to scanf, but I suck at pointers and returning chars. My code: char *getline(){ char *string; char c; int i=0;...
33
by: Jordan Tiona | last post by:
How can I make one of these? I'm trying to get my program to store a string into a variable, but it only stores one line. -- "No eye has seen, no ear has heard, no mind can conceive what God...
4
by: Alan | last post by:
How do I convert the type const char* to type char*? I have an input string ("input_string") of class string. I need to convert this to type char* in order to use it in a call to the strtok()...
8
by: amphetaman | last post by:
Is there a safe (unlikely to cause overflows or segfaults) way to load a text file into a char ** array? I thought of using getline, but it needs a fixed-length string, and I don't know how many...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.