How to use a defined struct from another source file?

前端 未结 7 1981
北恋
北恋 2020-12-06 02:18

I am using Linux as my programming platform and C language as my programming language.

My problem is, I define a structure in my main source file( main.c):



        
7条回答
  •  心在旅途
    2020-12-06 03:03

    Header file /* include this header file in both file1.c and file2.c

    strcut a {
    
    };
    
    struct b {
    
    }; 
    

    so header file included the declaration of both structures .

    file 1.c 
    

    strcut a xyz[10]; --> struct a defined here

    to use struct b here in this file

    extern struct b abc[20];
    
    /* now can use in this file */
    

    file2.c

    strcut b abc[20]; /* defined here */
    

    to use strcut a defined in file1.c

    use extern struct a xyz[10]
    

提交回复
热议问题