Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > How to integrate two c files

Reply
Thread Tools

How to integrate two c files

 
 
neha_chhatre@yahoo.co.in
Guest
Posts: n/a
 
      02-21-2008
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..............
 
Reply With Quote
 
 
 
 
Michael Mair
Guest
Posts: n/a
 
      02-21-2008
http://www.velocityreviews.com/forums/(E-Mail 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..............



-- 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.
 
Reply With Quote
 
 
 
 
Mark Bluemel
Guest
Posts: n/a
 
      02-21-2008
(E-Mail 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?
 
Reply With Quote
 
MisterE
Guest
Posts: n/a
 
      02-21-2008

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.


 
Reply With Quote
 
santosh
Guest
Posts: n/a
 
      02-21-2008
Mark Bluemel wrote:

> (E-Mail 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. 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.

 
Reply With Quote
 
Mark Bluemel
Guest
Posts: n/a
 
      02-21-2008
santosh wrote:
> Mark Bluemel wrote:
>
>> (E-Mail 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...)

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?
 
Reply With Quote
 
santosh
Guest
Posts: n/a
 
      02-21-2008
Mark Bluemel wrote:

> santosh wrote:
>> Mark Bluemel wrote:
>>
>>> (E-Mail 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.

 
Reply With Quote
 
Hyuga
Guest
Posts: n/a
 
      02-21-2008
On Feb 21, 3:56 am, Mark Bluemel <(E-Mail Removed)> wrote:
> (E-Mail 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?


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
 
Reply With Quote
 
David T. Ashley
Guest
Posts: n/a
 
      02-21-2008
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.

 
Reply With Quote
 
Flash Gordon
Guest
Posts: n/a
 
      02-21-2008
David T. Ashley wrote, On 21/02/08 17:45:
> <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
What is the simplest way to integrate two asp.net 2.0 webapplications? Author ASP .Net 1 01-19-2009 03:36 AM
How to compare two SOAP Envelope or two Document or two XML files GenxLogic Java 3 12-06-2006 08:41 PM
Can I integrate .EXE files into a new C program? pdmountaineer@hotmail.com C Programming 2 04-11-2006 09:55 AM
integrate two apps, Help!!! Paul nevegue ASP .Net 1 10-27-2003 02:53 PM



Advertisments