You are here:

C/Question about Structure in C

Advertisement


Question
struct names {
     char mine[7];
     char his[7];
};

struct names names;    

In here, why can't I do the variable declaring like this : "names names"? (without the struct keyword, because I think that "names" is already assigned as a structure).

Answer
Hi Miguel,

I believe you want to do something similar to this:


       typedef struct _names {
               char mine[7];
               char his[7];
       }names_t;

       names_t names;

       strcpy(names.mine, "abcdef");
       strcpy(names.his, "ghijkl");

       printf("names.mine = '%s'\nnames.his = '%s'\n",names.mine, names.his);


output:
names.mine = 'abcdef'
names.his = 'ghijkl'

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Tony Nazzal

Expertise

I will answer any c language programming and syntax questions.

Experience

I have almost a decade of c programming experience.

Education/Credentials
I have a bachelor of science degree and several years of industry experience.

©2016 About.com. All rights reserved.