I am so lost. I don't know what I'm doing. Can somebody help me? What I'm trying to do right now is just store ID numbers in an array to use them elsewhere in my program. I can't even do that right though. This is my first time taking computer science and I just don't get it.

#include <stdio.h>
#include <stdlib.h>

int GetID( int students, int StoreID[41], int i);

int main(void)
{
    int students;
    int StoreID[41];    
    int i;
    
    printf("Enter the number of students in the class:");
        scanf("%d", &students);

    GetID(students,StoreID[],i);

    return EXIT_SUCCESS;

}


int GetID( int students,int StoreID[41], int i)
{    

    printf("Student\n");

    for( i=0; i<students; i++)
    {
        printf("Enter student%d ID:", i+1);
        scanf("%d", &StoreID[i]);
        
    }

    printf("%d\n", StoreID[i]);

    return StoreID[i];

}

In function 'main':
15: Warning: passing argument 2 of 'GetID' makes pointer from integer without a cast.

Recommended Answers

All 7 Replies

>GetID(students,StoreID[],i);
That's not how you pass arrays. Remove the [], and you'll pass the address of it.

Great! That helps a lot! It works now! Thank you!

I'm completely screwed. This code doesn't actually store anything in my array, does it? I can enter the students' codes, however, thats all it allows me to do. I think I have the wrong idea about arrays.

>This code doesn't actually store anything in my array, does it?
Of course it does. You just aren't printing out any of the values you stored.

Try this at the end of GetID():

for (i=0; i<students; i++) {
        printf("%d\n", StoreID[i]);
    }

Print the entire array in main() after accepting user input and see if it is printing out any records, which it definitely should.

And why pass the variable 'i' when you can declare it as a local variable in the function itself. Passing it around won't serve you any purpose, will it?

StoreID[41] is a single int. Change the lines that use the function:
4: int GetID( int students, int StoreID[], int i);
15: GetID(students,StoreID,i);
22: int GetID( int students,int StoreID[], int i)

Also, try displaying the the array when you return to see if it's loaded properly. All you displayed is the single value of the ID after the last one entered...

Thanks a lot everyone for helping me. I'm really trying to understand this all and I've made the necessary changes so things look much better!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.