Reputation: 157
I have the following C code
File Name: abc.c
#include<stdio.h>
struct abc{
int xxx;
float yyy;
};
I need to access the above struct in another file called def.c
Could anybody explain me how i can achieve this?
Thanks!
Upvotes: 2
Views: 2014
Reputation: 3
//myheader.h
struct abc{
int xxx;
float yyy;
}obj;
//demo.c
# include"myheader.h"
# include"stdio.h"
int main(){
printf("\nENTER TWO VALUES : ");
scanf("%d %f",&obj.xxx,&obj.yyy);
printf("\nVALUES YOU ENTERED ARE : %d %f\n",obj.xxx,obj.yyy);
return 0;
}
Upvotes: -1
Reputation: 839
// mystructs.h
struct abc{
int xxx;
float yyy;
};
//abc.c
#include "mystructs.h"
struct abc var1;
//another_file.c
#include "mystructs.h"
struct abc var2;
Upvotes: 7