How to integrate two c files

Discussion in 'C Programming' started by neha_chhatre@yahoo.co.in, Feb 21, 2008.

  1. Guest

    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, 2008
    #1
    1. Advertising

  2. Michael Mair Guest

    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.
     
    Michael Mair, Feb 21, 2008
    #2
    1. Advertising

  3. Mark Bluemel Guest

    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?
     
    Mark Bluemel, Feb 21, 2008
    #3
  4. MisterE Guest

    <> wrote in message
    news:...
    > 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.
     
    MisterE, Feb 21, 2008
    #4
  5. santosh Guest

    Mark Bluemel wrote:

    > 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.
     
    santosh, Feb 21, 2008
    #5
  6. Mark Bluemel Guest

    santosh wrote:
    > Mark Bluemel wrote:
    >
    >> 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?
     
    Mark Bluemel, Feb 21, 2008
    #6
  7. santosh Guest

    Mark Bluemel wrote:

    > santosh wrote:
    >> Mark Bluemel wrote:
    >>
    >>> 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.
     
    santosh, Feb 21, 2008
    #7
  8. Hyuga Guest

    On Feb 21, 3:56 am, Mark Bluemel <> wrote:
    > 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
     
    Hyuga, Feb 21, 2008
    #8
  9. <> wrote in message
    news:...
    > 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.
     
    David T. Ashley, Feb 21, 2008
    #9
  10. Flash Gordon Guest

    David T. Ashley wrote, On 21/02/08 17:45:
    > <> wrote in message
    > news:...
    >> 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.
    --
    Flash Gordon
     
    Flash Gordon, Feb 21, 2008
    #10
  11. Mark Bluemel wrote:
    > 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?
     
    Mark McIntyre, Feb 21, 2008
    #11
  12. jacob navia Guest

    Mark McIntyre wrote:
    > Mark Bluemel wrote:
    >> 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?
    >


    Indeed. This is a good point.

    --
    jacob navia
    jacob at jacob point remcomp point fr
    logiciels/informatique
    http://www.cs.virginia.edu/~lcc-win32
     
    jacob navia, Feb 21, 2008
    #12
  13. Randy Howard Guest

    On Thu, 21 Feb 2008 15:10:11 -0600, Mark McIntyre wrote
    (in article <VMlvj.698$2.easynews.com>):

    > Mark Bluemel wrote:
    >> 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?


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


    --
    Randy Howard (2reply remove FOOBAR)
    "The power of accurate observation is called cynicism by those
    who have not got it." - George Bernard Shaw
     
    Randy Howard, Feb 22, 2008
    #13
  14. Richard Bos Guest

    Randy Howard <> wrote:

    > On Thu, 21 Feb 2008 15:10:11 -0600, Mark McIntyre wrote
    >
    > > Mark Bluemel wrote:
    > >> 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?

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


    That is _very_ easy to say from the comfortable USA.

    Richard
     
    Richard Bos, Feb 22, 2008
    #14
  15. santosh Guest

    Randy Howard wrote:

    > On Thu, 21 Feb 2008 15:10:11 -0600, Mark McIntyre wrote
    > (in article <VMlvj.698$2.easynews.com>):
    >
    >> Mark Bluemel wrote:
    >>> 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?

    >
    > 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.
     
    santosh, Feb 22, 2008
    #15
  16. Richard Bos Guest

    santosh <> wrote:

    > Randy Howard wrote:
    >
    > > 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).


    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
     
    Richard Bos, Feb 22, 2008
    #16
  17. Randy Howard <> writes:
    > On Thu, 21 Feb 2008 15:10:11 -0600, Mark McIntyre wrote
    > (in article <VMlvj.698$2.easynews.com>):
    >> Mark Bluemel wrote:
    >>> 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?

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

    --
    Keith Thompson (The_Other_Keith) <>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Feb 22, 2008
    #17
  18. Randy Howard wrote:
    > On Thu, 21 Feb 2008 15:10:11 -0600, Mark McIntyre wrote
    > (in article <VMlvj.698$2.easynews.com>):
    >
    >> Mark Bluemel wrote:
    >>> 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?

    >
    > 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.
     
    Mark McIntyre, Feb 22, 2008
    #18
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul nevegue

    integrate two apps, Help!!!

    Paul nevegue, Oct 27, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    362
    Konrad Rotuski
    Oct 27, 2003
  2. GenxLogic
    Replies:
    3
    Views:
    1,350
    andrewmcdonagh
    Dec 6, 2006
  3. Replies:
    2
    Views:
    331
    Keith Thompson
    Apr 11, 2006
  4. Replies:
    2
    Views:
    354
    Vladimir S. Oka
    Apr 11, 2006
  5. Author
    Replies:
    1
    Views:
    586
    densial
    Jan 19, 2009
Loading...

Share This Page