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

    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

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

    which takes it...

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

    which collects it with

    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
    The edge of the known universe
    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 as the first necessary step to a free Europe.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    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
    I take it you mean
    >progname filename1 filename2

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

    pass them as pointers
    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
    If you use
    Then f1()'s prototype would look something like this:
    void f1(char *filename);

    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:

    My website:
    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, 05:58 PM
  5. Replies: 1
    Last Post: 01-20-2002, 10:50 AM

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