Hi. I'm a first year C student. I'm doing a homework assignment and I'm getting a strange result.
We have to use an array to display our initials in rows and columns made out of the letters in the initials. My initials are SR, so I need to make a S out of S's and an R out of R's. Then we have to search the array to see how many letters are in the array.

I made a function that would search the array using a for loop and a simple if statement. It will count each time it finds a specific character in the array. Then the function returns the total value.

I want to use sizeof( array ); in my for loop initialization so it knows how far to go, but when I sizeof() inside the function, it only reports a size of "4". When I use sizeof() in my main function, it reports the proper size of "105". Since I'm only using one array, and I know how many elements are in it, I've cheated and just set my for loop to run 105 times.

Anyone know what I'm missing? I have a feeling it's the way I've set up the array, but it's based on the examples we were shown in class on how to initialize arrays. Thanks for the help in advance!

Code:
/**
*Program Name:  cis26Fall2009StevenRiedelLab1Ex5.c
*Written By:    Steven Riedel
*Discussion:    using char arrays
*/

#include <stdio.h>

/* Funcion is designed to take an array and a char
 * and then using a for loop, count the char's
 * in the array that match the key.
 */

int searchArray( char search[], char key ) {

        /* line below to test the sizeof array to the passed array
         */
        printf( "size of array being passed: %d \n", sizeof( search ) );

        int i;
        int count = 0;

        /* the for statement I would like to use:
         * for ( i = 0; i < sizeof( search); i++ ) {
         */

        for ( i = 0; i < 105; i++ ) {
                if ( search[ i ] == key )
                        count++;
        }
return count;
}


int main( void ) {

        /* setting up counters to track the S's and R's
         */

        int rCount = 0;
        int sCount = 0;

        /* Making the SR out of a char array
         */

        char cAry1[ ] = " SSS   RRRRRR \n"
                        "S   S  R     R\n"
                        " S     R     R\n"
                        "  S    RRRRRR \n"
                        "   S   R    R \n"
                        "S   S  R     R\n"
                        " SSS   R     R";

        /* using puts to dispay SR
         */

        puts ( cAry1 );

        /* running array thought the searchArray() function.
         * and storing the returned value into sCount and rCount
         */

        /* Line below added to test the sizeof() function
         */
        printf( "Size of array in main method: %d \n", sizeof( cAry1 ) );

        sCount += searchArray( cAry1, 'S' );
        rCount += searchArray( cAry1, 'R' );

        /* print the final results of sCount and rCount
         */

        printf( "\nThere are %d S's and %d R's\n", sCount, rCount );

return 0;

}
/*
OUTPUT
 SSS   RRRRRR
S   S  R     R
 S     R     R
  S    RRRRRR
   S   R    R
S   S  R     R
 SSS   R     R
Size of array in main method: 105
size of array being passed: 4
size of array being passed: 4

There are 13 S's and 22 R's
*/