Dynamic allocation of memory

K

kupiko

Hello i'm working on problem of dynamic allocation of memory.
I would like to have variable char name[?] set in the way to be able to
change the memory it uses while program is running for ex. I will type
name Kupiko and i would like my variable name to be that large no more no
less. Not just to set the amount of char to name[20]. Please could anyone
advice me how to do it?
 
R

Russell Shaw

kupiko said:
Hello i'm working on problem of dynamic allocation of memory.
I would like to have variable char name[?] set in the way to be able to
change the memory it uses while program is running for ex. I will type
name Kupiko and i would like my variable name to be that large no more no
less. Not just to set the amount of char to name[20]. Please could anyone
advice me how to do it?

man 3 getline
 
R

Richard Bos

kupiko said:
Hello i'm working on problem of dynamic allocation of memory.
I would like to have variable char name[?] set in the way to be able to
change the memory it uses while program is running for ex. I will type
name Kupiko and i would like my variable name to be that large no more no
less. Not just to set the amount of char to name[20]. Please could anyone
advice me how to do it?

Yes. Look up "malloc" and "realloc" in the index of your C text book.

Richard
 
R

Richard Bos

Russell Shaw said:
kupiko said:
Hello i'm working on problem of dynamic allocation of memory.
I would like to have variable char name[?] set in the way to be able to
change the memory it uses while program is running for ex. I will type
name Kupiko and i would like my variable name to be that large no more no
less. Not just to set the amount of char to name[20]. Please could anyone
advice me how to do it?

man 3 getline

Since when is that ISO C? Note that you have no idea what kind of system
the OP is on; it need not have POSIX (or whatever extension getline is)
at all.

Richard
 
C

CBFalconer

kupiko said:
Hello i'm working on problem of dynamic allocation of memory.
I would like to have variable char name[?] set in the way to be
able to change the memory it uses while program is running for ex.
I will type name Kupiko and i would like my variable name to be
that large no more no less. Not just to set the amount of char to
name[20]. Please could anyone advice me how to do it?

Use ggets. Available at:

<http://cbfalconer.home.att.net/download/>
 
D

Default User

Richard said:
Russell Shaw said:
kupiko said:
Hello i'm working on problem of dynamic allocation of memory.
I would like to have variable char name[?] set in the way to be able to
change the memory it uses while program is running for ex. I will type
name Kupiko and i would like my variable name to be that large no more no
less. Not just to set the amount of char to name[20]. Please could anyone
advice me how to do it?

man 3 getline

Since when is that ISO C? Note that you have no idea what kind of system
the OP is on; it need not have POSIX (or whatever extension getline is)
at all.


It's not even POSIX, it's C++ for use with the std::string template
class.



Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,955
Messages
2,570,117
Members
46,705
Latest member
v_darius

Latest Threads

Top