LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 11-18-2002, 08:51 AM   #1
JStew
Member
 
Registered: Oct 2002
Location: North Atlanta
Distribution: LFS
Posts: 229

Rep: Reputation: 30
Assigning a string to a variable (not a pointer, not a array)


This is for C, not Perl or anything else... just C...

is it even possible to store a word, sentence as a string literal to a variable... this variable needs to just be a char variable (or the like) and not a pointer or array.. can it be done???
 
Old 11-18-2002, 08:53 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,415

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
well not as a char, as a char is just a single byte, which is the point of using a pointer to a char array instead...
 
Old 11-18-2002, 09:03 AM   #3
JStew
Member
 
Registered: Oct 2002
Location: North Atlanta
Distribution: LFS
Posts: 229

Original Poster
Rep: Reputation: 30
Is there a way maybe without using char? Is there any way possible at all to store a word or phrase to just one variable? Is there a header file that supports any function that would do this?
 
Old 11-18-2002, 09:13 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,415

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
there is no native string datatype in C. C++ has a String class, but a string is fundamentally non-primitive, so not present in C. you can get by with something like...

Code:
char* string;
string = "help me";
so you can treat it as a string, even though it is just a pointer to an array of characters. Mind you, that's all a string ever is in C++, it's just hidden from you.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
in C, Assigning output of system() to a variable Miaire Programming 4 01-30-2005 01:40 PM
assigning memory address to pointer irfanhab Programming 4 04-24-2004 04:35 AM
java test if string in string array is null. exodist Programming 3 02-21-2004 02:39 PM
Assigning the output of one command to a variable (shell) guru_stew Programming 5 08-03-2003 07:12 PM
C programming assigning an integer value to a string Linh Programming 4 06-22-2003 08:02 AM


All times are GMT -5. The time now is 06:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration