Thread: Passing arguments between functions

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    145

    Passing arguments between functions

    I'm trying to take 2 filenames as arguments in my C program, then pass the second argument to another function, which does nothing to it but then passes it on to another function.

    I'm starting the program using

    Code:
    int main(int argc, char *argv[])
    Passing it to another function with

    Code:
    f1(argv)
    which takes it...

    Code:
    f1(char *argv[]
    passing it to another function with

    Code:
    f2(argv)
    which collects it with

    Code:
    f2(char *argv[])

    When I try and compile, it says I'm passing an incompatible pointer type. What am I doing wrong?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    No idea - perhaps you don't prototype your functions.

    Post some actual code you compiled, not random lines.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Can you post something we can actually compile to see your problem? Also, what compiler are you using and on what OS?
    My best code is written with the delete key.

  4. #4
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    I take it you mean
    >progname filename1 filename2

    filename1 is argv[1]
    filename2 is argv[2]

    pass them as pointers
    Code:
    f1(argv[1]);
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    If you use
    Code:
    f1(argv[1]);
    Then f1()'s prototype would look something like this:
    Code:
    void f1(char *filename);
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Functions Taking Dif. Numbers of Arguments at Dif. Times?
    By bengreenwood in forum C++ Programming
    Replies: 6
    Last Post: 03-23-2009, 04:12 PM
  2. Problem Passing Values between functions
    By jamez05 in forum C++ Programming
    Replies: 2
    Last Post: 05-02-2007, 01:21 PM
  3. Passing functions between files
    By Duskan in forum C Programming
    Replies: 9
    Last Post: 04-17-2007, 07:44 AM
  4. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 06:58 PM
  5. Replies: 1
    Last Post: 01-20-2002, 11:50 AM