Thread: passing arrays

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    5

    passing arrays

    I'm having some trouble figuring out how to pass arrays. I need to write a function with 3 parameters: a,b,i. A and B are char arrays. The parameter i is an int. The function inserts the string a into b immediately after index i. Assume b is large enough to hold the added characters.
    So an example of what I'm trying to do is the following...
    A is "Today Wednesday"
    b is "is"
    i is 6
    and the result of the function would be
    Today is Wednesday

    So far I have this, the for loop finds the length of the string but I'm not sure how to write the function
    #include <stdio.h>
    #include <stdlib.h>
    main()
    {
    int i;
    char a[];
    char b[];

    for ( i = 0; a[i] != '\0'; i++ );
    return i;
    Last edited by Sarah; 10-24-2001 at 07:55 PM.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    myfunction( char array1[], char array2[], int x )
    {
    }


    call:

    myfunction( arrayA, arrayB, varX );


    On multiple dimension arrays, for a function definition, you can only omit the first [] size. All others must define the size of the array:

    myfunction2( int array[][5][10] )

    Called the same:

    myfunction2( myMultiDimensionalArray );


    Quzah.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. More trouble passing arrays
    By Rad_Turnip in forum C Programming
    Replies: 2
    Last Post: 04-04-2006, 08:11 PM
  2. Passing pointers to arrays of char arrays
    By bobthebullet990 in forum C Programming
    Replies: 5
    Last Post: 03-31-2006, 05:31 AM
  3. Having Trouble Passing typedef Arrays to a Function
    By jlharrison in forum C Programming
    Replies: 1
    Last Post: 03-27-2006, 12:06 PM
  4. Help Understanding Passing Arrays To Functions
    By jrahhali in forum C++ Programming
    Replies: 7
    Last Post: 04-10-2004, 02:57 PM
  5. passing arrays to functions
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 03-01-2002, 03:18 PM