I create two C files, one is main.c and another is test.c,and then I defined an struct verb in test.c:
struct image{
int a;
char b;
};
struct image ss;
void test() {
ss.a = 10;
}
I want to use the struct verb ss in the main.c,but I failed. Please help me how can I use the struct verb ss in the main.c.
Thank you very much
Thank you, I think I am a new man, I want you tell me how can I define struct verb in test.h,may is define extern struct image ss in the test.h. That struct image{
int a;
char b;
}; in test.c
I do this but failed!
Thank you, Thank you!
3 2088
Create a header file name test.h
then define struct verb in test.h file. include the test.h file in main.c and so on
Thank you, I think I am a new man, I want you tell me how can I define struct verb in test.h,may is define extern struct image ss in the test.h. That struct image{
int a;
char b;
}; in test.c
I do this but failed!
Thank you, Thank you!
Oh, I solved the problem by johny, I have a little opinion about the using of the keyword struct. I think the struct verb is the new data struct by yourself, that you can't put definition of the struct in the program file, or the compile machine say the struct is not define, so, you can not do this like use int, char or other data struct that define in c compile. That in other C file is already know the int or char data struct, so you can int a in a C file, and define it in a header file. Like this define a global verb: int a int test.c and referencing declaration: extern a in test.h and change it in main.c. Then you use struct verb you can not do like this, that struct s{int a;}; struct s x; in test.c and extern x; in test.h, then change it in main.c--x.a=10;, or the compile machine think it is a error, because it is not know the s struct data struct, you must define the struct s{int a;}; in test.h and int main.c file include the test.h, referencing declaring of it at last, and you will succeed to change it.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Roy Hills |
last post by:
When I'm reading from or writing to a network socket, I want to use a
struct to represent the structured data, but must use an unsigned char
buffer for the call to sendto() or recvfrom().
I have...
|
by: Rick Anderson |
last post by:
All,
I am receiving the following compilation error on LINUX
(but not Solaris, HPUX, WIN32, etc):
compiling osr.c
LBFO.h(369): warning #64: declaration does not declare anything
extern...
|
by: PCHOME |
last post by:
Hello! I am working on dividing a single C file into several files.
Now I encounter a problem about the global variables
and can not find a way to solve it.
All global variables and codes used...
|
by: Russell Shaw |
last post by:
Hi,
I have two structs in a header file, and they reference each other,
causing a compile error. Is there a standard way to deal with this?
typedef struct {
...
RtAction *actions;
}...
|
by: S.Tobias |
last post by:
I'm trying to understand how structure type completion works.
# A structure or union type of unknown
# content (as described in 6.7.2.3) is an incomplete type. It
# is ...
|
by: burn |
last post by:
Hello,
i am writing a program under linux in c and compile my code with make
and gcc.
Now i have 4 files: init.c/h and packets.c/h. Each header-file contains
some:
init.h:
struct xyz
{
|
by: PCHOME |
last post by:
Hi!
I have questions about qsort( ). Is anyone be willing to help?
I use the following struct:
struct Struct_A{
double value;
...
} *AA, **pAA;
|
by: Alex |
last post by:
If I have two struct. See below:
struct s1
{
int type;
int (*destroy)(struct s1* p);
}
struct s2
{
struct s1 base;
|
by: hobbes992 |
last post by:
Howdy folks,
I've been working on a c project, compiling using gcc, and I've reached a problem. The assignment requires creation of a two-level directory file system. No files have to be added or...
|
by: hugo.arregui |
last post by:
Hi!
I have two struts like that:
struct {
int num;
int num2;
struct b arrayOfB;
} a;
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |