vcth4nh
vcth4nh

Reputation: 149

#define structure name in C

Is it possible/ is there any way to write something like this in the .h file?

#define _struct 'profile'


int output(_struct list[],int n)
{
    for (int i=0; i<n; i++) {
        printf("%s\n"list[i].name);
    }
}

In the .c file, I declare the struct name (profile in this example) and in the header file I define the struct name like above. My aim is when another .c file use this header, I only have to change the structure name in #define.

Upvotes: 1

Views: 58

Answers (1)

Pablo Santa Cruz
Pablo Santa Cruz

Reputation: 181270

Apparently you are trying to achieve something like C++ templates but in C.

Although it is not possible in C to achieve this kind of behavior, take a look at this answer which is trying to accomplish something similar using macros.

Upvotes: 2

Related Questions