LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] Hi, just a quick question (again!!)

[ILUG] Hi, just a quick question (again!!)

Colm Buckley colm at tuatha.org
Tue Apr 13 10:52:53 IST 1999


> Hi, I have just created a C program that uses structures.  My trouble is
> that whn I define a field in the structure as an array of char for a
> string, I get an error when I try to initialise the value.

Nope.

To *copy* a string from one place to another, use strcpy().  In your
example, conn_inst[0].name should be initialised using:

strcpy(conn_inst[0].name, "Blah Blah Blah");

If your strings were always constants, or pointers to other strings, you
could have declared it as:

struct instrument {
       char *name;
...
};

...

conn_inst[0].name = "Blah Blah Blah";

However, this just sets up conn_inst[0].name to *point* to the constant
string "Blah Blah Blah".  If you're unclear on this, I suggest taking a
close look at the sections of your books which discuss pointers and
arrays.

            Colm

-- 
Colm Buckley B.A. B.F. <colm at tuatha.org> | <colm.buckley at cs.tcd.ie>
Department of Computer Science      # +353 87 2469146 # whois cb3765
Trinity College, Dublin 2, Ireland. # http://www.tuatha.org/~colm/
You never really learn to swear until you learn to drive.




More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


Maintained by the ILUG website team. The aim of Linux.ie is to support and help commercial and private users of Linux in Ireland. You can display ILUG news in your own webpages, read backend information to find out how. Networking services kindly provided by HEAnet, server kindly donated by Dell. Linux is a trademark of Linus Torvalds, used with permission. No penguins were harmed in the production or maintenance of this highly praised website. Looking for the Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!
RSS Version
Powered by Dell