Thread: A question about structure and array

  1. #1
    Registered User
    Join Date
    Feb 2010

    A question about structure and array

    Suppose I have the following structure and array.
    typedef struct name {
    	char firstName[20];
    	char lastName[20];
    } name
    name nameList[100];
    Can I assume that nameList[i].firstName and nameList[i].lastName always have a size of 20?

    Is strcpy the only way to store data into this name struct array?
    (e.g. strcpy(nameList[i].firstName, "John")

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Yes and yes. (Unless you count scanf-ing directly into that field.)

  3. #3
    "I Win!" by U. Lose vart's Avatar
    Join Date
    Oct 2006
    Rishon LeZion, Israel
    there is also sprintf
    To be or not to be == true

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  2. Dynamic structure with array and array count
    By Nazgulled in forum C Programming
    Replies: 14
    Last Post: 06-08-2007, 10:10 PM
  3. Multidimensional Array in a Structure
    By Night_Blade in forum C Programming
    Replies: 3
    Last Post: 04-04-2005, 08:14 PM
  4. Array and Structure Question
    By loopshot in forum C++ Programming
    Replies: 2
    Last Post: 10-21-2004, 05:10 PM
  5. Filling an array in a structure
    By thephreak6 in forum C Programming
    Replies: 1
    Last Post: 12-16-2002, 05:05 PM
Website Security Test