How to integrate two c files

N

neha_chhatre

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..............
 
M

Michael Mair

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
 
M

Mark Bluemel

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?
 
M

MisterE

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.
 
S

santosh

Mark said:
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.
 
M

Mark Bluemel

santosh said:
Mark said:
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.

So we are expected to provide free tuition to make up for that?
(There are decent online tutorials available for free apparently...)

Anyway, if we assume that people are learning C as a means of
improving employment prospects, what is the cost of a decent book
when regarded as an investment?
 
S

santosh

Mark said:
santosh said:
Mark said:
(e-mail address removed) 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.

So we are expected to provide free tuition to make up for that?
(There are decent online tutorials available for free apparently...)

Didn't say that. I was only explaining.
Anyway, if we assume that people are learning C as a means of
improving employment prospects, what is the cost of a decent book
when regarded as an investment?

I guess it depends on the person in question.
 
H

Hyuga

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?

Reminds me of the anime "Golden Boy", in which the protagonist teaches
himself how to program over the course of a weekend, on a keyboard he
drew on a piece of cloth, by candle light. He shows up for work, and
over the course of a week or so codes up a sophisticated GUI-driven
application, while working full time as a janitor at a software
company. The OP should note that this was fiction, and intended as
comedy, and he should not expect the same results.

Hyuga
 
D

David T. Ashley

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/esrgpcpj/shared/c_datd/esrg_md5.h?revision=1.8&view=markup

http://esrg.cvs.sourceforge.net/esrg/esrgpcpj/shared/c_datd/esrg_md5.c?revision=1.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.
 
F

Flash Gordon

David T. Ashley wrote, On 21/02/08 17:45:
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/esrgpcpj/shared/c_datd/esrg_md5.h?revision=1.8&view=markup


http://esrg.cvs.sourceforge.net/esrg/esrgpcpj/shared/c_datd/esrg_md5.c?revision=1.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.
 
M

Mark McIntyre

Mark said:
Anyway, if we assume that people are learning C as a means of
improving employment prospects, what is the cost of a decent book
when regarded as an investment?

To be fair tho, whats the cost of a decent book, even as an investment,
when you earn $5 a day and need to feed a large family?
 
J

jacob navia

Mark said:
To be fair tho, whats the cost of a decent book, even as an investment,
when you earn $5 a day and need to feed a large family?

Indeed. This is a good point.
 
R

Randy Howard

To be fair tho, whats the cost of a decent book, even as an investment,
when you earn $5 a day and need to feed a large family?

If you make no money, perhaps you shouldn't be spawning a large family.
 
R

Richard Bos

Randy Howard said:
To be fair tho, whats the cost of a decent book, even as an investment,
when you earn $5 a day and need to feed a large family?

If you make no money, perhaps you shouldn't be spawning a large family.[/QUOTE]

That is _very_ easy to say from the comfortable USA.

Richard
 
S

santosh

Randy said:
If you make no money, perhaps you shouldn't be spawning a large
family.

This isn't an issue in urban areas and even with semi-educated people.
The problem is that most of these posters are likely to be students and
parents rarely allow buying $10-15 books. There are also, as Mark notes
many people earning ~$4 a day and obliged to spend some of it on family
(not necessarily a large one and not always their own). Even people
with adequate money are still circumspect when it comes to expenditure;
a cultural holdover from the past when money really was hard to come by
and relatively more precious.

Western type consumption is still confined pretty much to the segment
earning more than $20 a day, still by and large, a comparatively small
one.
 
R

Richard Bos

santosh said:
This isn't an issue in urban areas and even with semi-educated people.
The problem is that most of these posters are likely to be students and
parents rarely allow buying $10-15 books. There are also, as Mark notes
many people earning ~$4 a day and obliged to spend some of it on family
(not necessarily a large one and not always their own).

Of course, in the West book prices are also higher (but not quite
proportionally); but in the West, students can often get a student loan
or scholarship of one kind or another. I doubt that those are commonly
available in India, let alone in even poorer countries.

Richard
 
K

Keith Thompson

Randy Howard said:
If you make no money, perhaps you shouldn't be spawning a large family.

I suggest that lecturing people in poor countries about how many
children they should have is, if nothing else, off-topic for this
newsgroup.
 
M

Mark McIntyre

Randy said:
If you make no money, perhaps you shouldn't be spawning a large family.

Apparently you're an idiot. Go work out what the wages are for
computer-illiterate folk are in Bangalore.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top