Results 1 to 2 of 2
  1. #1
    Join Date
    May 2004

    Unhappy Unanswered: In desperate need of help!!

    Hey guys, this is my first time posting here, but I've used the forums to find help before

    I'm in a jam, my final C program is due and I still can't get it to work.

    I'm trying to return an int array from a function to the main for use in other functions, but it won't let me return it.

    Function Declaration:

    int calcFreq(int Ratings[], int Freq[], int NumStudents);
    Function Call:

    Freq[] = calcFreq(Ratings, Freq, NumStudents);
    Function Body:

    int calcFreq(int Ratings[], int Freq[], int NumStudents)

    int i = 0;

    for (i = 0; i < NumStudents; i++)
    Freq[Ratings[i]-1] = Freq[Ratings[i]-1] + 1;
    return Freq[];
    Thanks for any help you can provide!

  2. #2
    Join Date
    Mar 2004

    Exclamation You have a small error

    Your function calcFreq does not return an array, I recommend you to return a 0 or -1 to indicate error/success instead of trying to return an array:

    return Freq[]; /* this is wrong */

    return 0; /* this is wright */
    return i; /* this is wright */

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts