Passing arguments between functions

This is a discussion on Passing arguments between functions within the C Programming forums, part of the General Programming Boards category; I'm trying to take 2 filenames as arguments in my C program, then pass the second argument to another function, ...

  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
    32,832
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    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,161
    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,048
    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, 05:12 PM
  2. Problem Passing Values between functions
    By jamez05 in forum C++ Programming
    Replies: 2
    Last Post: 05-02-2007, 02:21 PM
  3. Passing functions between files
    By Duskan in forum C Programming
    Replies: 9
    Last Post: 04-17-2007, 08: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21