473,503 Members | 7,214 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to integrate two c files

hello
i have a problem... have written two separate c files named read.c
and twinkle.c

the file read.c, after running stores some values in an array name
average[] and it has a count variable k......

now i need to read both average[] and the variable k from the
twinkle.c file

How do i integrate the two files r in short..how do i read the values
of average[] and count variable k from twinkle.c

Please help me urgently..............
Feb 21 '08 #1
6 1841
ne**********@yahoo.co.in wrote:
hello
i have a problem... have written two separate c files named read.c
and twinkle.c

the file read.c, after running stores some values in an array name
average[] and it has a count variable k......

now i need to read both average[] and the variable k from the
twinkle.c file

How do i integrate the two files r in short..how do i read the values
of average[] and count variable k from twinkle.c

Please help me urgently..............

-- program.c --
#include "read.h"
#include "twinkle.h"

int main(void)
{
int k = 0;
int* array = 0;
MyRead(&array, &k);
if (NULL == array)
{
MyTwinkle(array, k);
}
MyReadCleanup(&array, k);
return 0;
}
----
-- read.h --
void MyRead (int **pArray, int *pK);
void MyReadCleanup (int **pArray, int k);
----
-- twinkle.h --
void MyTwinkle (int *array, int k);
----

Fill in twinkle.c, read.c as necessary.

Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Feb 21 '08 #2
ne**********@yahoo.co.in wrote:
hello
i have a problem... have written two separate c files named read.c
and twinkle.c

the file read.c, after running stores some values in an array name
average[] and it has a count variable k......

now i need to read both average[] and the variable k from the
twinkle.c file

How do i integrate the two files r in short..how do i read the values
of average[] and count variable k from twinkle.c

Please help me urgently..............
Are you (yet) another of those people trying to teach themselves C
without reading a decent book or tutorial?
Feb 21 '08 #3

<ne**********@yahoo.co.inwrote in message
news:5d**********************************@f47g2000 hsd.googlegroups.com...
hello
i have a problem... have written two separate c files named read.c
and twinkle.c

the file read.c, after running stores some values in an array name
average[] and it has a count variable k......

now i need to read both average[] and the variable k from the
twinkle.c file

How do i integrate the two files r in short..how do i read the values
of average[] and count variable k from twinkle.c

Please help me urgently.............
The easiest and most nasty way is to declare the variables as global
variables. So you would have somesomething like:
char avarage[100];
int index=0;
in read.c,
then in twinkle.c you can use them by defining:
extern char average[100];
extern int index;

the extern means they are externally declared in another file.
Feb 21 '08 #4
Mark Bluemel wrote:
ne**********@yahoo.co.in wrote:
>hello
i have a problem... have written two separate c files named read.c
and twinkle.c

the file read.c, after running stores some values in an array name
average[] and it has a count variable k......

now i need to read both average[] and the variable k from the
twinkle.c file

How do i integrate the two files r in short..how do i read the values
of average[] and count variable k from twinkle.c

Please help me urgently..............

Are you (yet) another of those people trying to teach themselves C
without reading a decent book or tutorial?
To be fair K&R2, Harbison & Steele, K.N. King's C Programming: A Modern
Approach are typically not stocked in bookshops here. And if they are,
they are usually far beyond the budget of most people. Their best
choice is to shop for a used version on Amazon and similar sites. Local
authors are cheap enough, but unfortunately, both in cost and quality.

Feb 21 '08 #5
<ne**********@yahoo.co.inwrote in message
news:5d**********************************@f47g2000 hsd.googlegroups.com...
i have a problem... have written two separate c files named read.c
and twinkle.c

the file read.c, after running stores some values in an array name
average[] and it has a count variable k......

now i need to read both average[] and the variable k from the
twinkle.c file

How do i integrate the two files r in short..how do i read the values
of average[] and count variable k from twinkle.c
Generally speaking, .H files allow you to declare an interface to the
corresponding .C file, which may include global variables.

When you start using .H files, there are a few things you want to provide
for:

a)A given include file should "stand alone", i.e. not require the inclusion
of any other files. (The generally requires that it itself include files,
and requires some mechanism that deals with multiple inclusion).

b)You want to avoid identifying the characteristics of anything in more than
one place (change and consistency risk).

c)You want full prototype linkage--you want the definition of a function
checked against the prototype, and the prototype checked against the
invocations.

Here are some sample files that may be a suitable example:

http://esrg.cvs.sourceforge.net/esrg....8&view=markup

http://esrg.cvs.sourceforge.net/esrg...10&view=markup

Unfortunately the examples above don't have any global data, but it can be
placed in the .H file using the DECMOD_ ... construct.

For example:

DECMOD_MYMODULE int bart_simpsons_iq_readings[5]
#ifdef MODULE_MYMODULE
= {32, 49, 57, 23, 33}
#endif
;

Note that this expands a bit differently when compiling the owning module
rather than others.

Dave.

Feb 21 '08 #6
David T. Ashley wrote, On 21/02/08 17:45:
<ne**********@yahoo.co.inwrote in message
news:5d**********************************@f47g2000 hsd.googlegroups.com...
>i have a problem... have written two separate c files named read.c
and twinkle.c

the file read.c, after running stores some values in an array name
average[] and it has a count variable k......

now i need to read both average[] and the variable k from the
twinkle.c file

How do i integrate the two files r in short..how do i read the values
of average[] and count variable k from twinkle.c

Generally speaking, .H files allow you to declare an interface to the
corresponding .C file, which may include global variables.
On some implementations the case of the extension affects how the
compiler treats it so, traditionally, that should be .h and .c if you
are programming in C. Note that on some of these implementations .C will
cause the code to be compiled as C++.
When you start using .H files, there are a few things you want to
provide for:

a)A given include file should "stand alone", i.e. not require the
inclusion of any other files. (The generally requires that it itself
include files, and requires some mechanism that deals with multiple
inclusion).

b)You want to avoid identifying the characteristics of anything in more
than one place (change and consistency risk).

c)You want full prototype linkage--you want the definition of a function
checked against the prototype, and the prototype checked against the
invocations.
To achieve all of c you need to include the header file in the source
file that provides the definitions. I.e. a.c should #include a.h
Here are some sample files that may be a suitable example:

http://esrg.cvs.sourceforge.net/esrg....8&view=markup
http://esrg.cvs.sourceforge.net/esrg...10&view=markup
Unfortunately the examples above don't have any global data, but it can
be placed in the .H file using the DECMOD_ ... construct.

For example:

DECMOD_MYMODULE int bart_simpsons_iq_readings[5]
#ifdef MODULE_MYMODULE
= {32, 49, 57, 23, 33}
#endif
;

Note that this expands a bit differently when compiling the owning
module rather than others.
Many people don't like that style and would prefer a simple declaration
in the header and definition in the .c, i.e.

a.h
extern int bart_simsons_iq_readings[5];

a.c
#include <a.h>
int bart_simsons_iq_readings[5] = {32,49,23,33};

The compiler is guaranteed to report any mismatch because of the
inclusion of a.h so there is no risk of a type mismatch being missed.
--
Flash Gordon
Feb 21 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1341
by: Rob R. Ainscough | last post by:
I'm looking for some Knowledge base tools that would integrate into VS.2003 and be flexible. My developers would us it to house important tips, tricks, and other information -- needs to have...
3
9460
by: Tom Kaz | last post by:
I need to compute integral of some array function, something like: from scipy import * f = lambda x: array( ) integrate.quad(f, 0, 1) Unfortunately integrate.quad requires Float type.
5
2637
by: Marcelo | last post by:
How can I integrate c++ programs inside a GUI java interface? I would like to get the results from a c++ program and integrate them inside a java GUI. thanks Marcelo
0
2251
by: Fred Mellender | last post by:
I had VC# 2003 installed and then installed the Managed DirectX SDK. When I highlight a Direct3D class (e.g. Device) and press F1, I get the help page from the SDK and everything works fine within...
4
1899
by: velmj | last post by:
I need to integrate an asp.net module into an existing asp site. How can I do this?. Can i create a subdirectory and put all the asp.net files into it, and reference the default.aspx file from...
2
2204
by: pdmountaineer | last post by:
hi, I am writing a C program and I would like to integrate some executables (.EXE files) from my C program. Is this possible and how should one do this exactly? kind regards
3
2636
by: pdmountaineer | last post by:
hi, I would like to integrate some executable files (.EXE files) into a new C program. Is this possible and if so, how should it be done exactly??? kind regards
4
1627
by: smurph | last post by:
We have a web application project, currently this is in sourcesafe. What I want is the developers to edit, debug and save the files locally on their own machine, then when they check in the file it...
1
1933
by: Prajaktaj | last post by:
Hi All, I have created one web service in java which contain one web method called getItemDetails(). I have also created one web service in .Net which contains another 4 web methods. I want to...
0
7207
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7291
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7012
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5598
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3171
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.