pre-defined array of strings within a structure

This is a discussion on pre-defined array of strings within a structure within the C Programming forums, part of the General Programming Boards category; Why is the following syntax not legal? Code: struct additives { char* milk[7]; = { "Skimmed", "Frothy", "half-skim", "Cream" }; ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    66

    pre-defined array of strings within a structure

    Why is the following syntax not legal?

    Code:
    struct additives {
    	char* milk[7]; = { "Skimmed", "Frothy", "half-skim", "Cream" };	
    };

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    First might be the misplaced semicolon. Second might be that types don't have values, objects do -- so you cannot initialize a type. Create an object of your type and provide an initialization there instead. Maybe something like this.
    Code:
    struct additives {
    	char* milk[7];	
    };
    
    struct additives Object =
    {
       { "Skimmed", "Frothy", "half-skim", "Cream" }
    };
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 04-27-2008, 04:39 AM
  2. Structure array problem
    By Birdhaus in forum C++ Programming
    Replies: 2
    Last Post: 11-21-2005, 09:59 PM
  3. remove strings from array
    By ipe in forum C Programming
    Replies: 2
    Last Post: 01-12-2003, 04:53 AM
  4. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 09:31 AM
  5. Moving to the next structure array
    By mattz in forum C Programming
    Replies: 2
    Last Post: 11-30-2001, 03:43 PM

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