A question about structure and array

This is a discussion on A question about structure and array within the C Programming forums, part of the General Programming Boards category; Suppose I have the following structure and array. Code: typedef struct name { char firstName[20]; char lastName[20]; } name name ...

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    32

    A question about structure and array

    Suppose I have the following structure and array.
    Code:
    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
    Posts
    14,185
    Yes and yes. (Unless you count scanf-ing directly into that field.)

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    there is also sprintf
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

Popular pages Recent additions subscribe to a feed

Similar Threads

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21