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);


    return EXIT_SUCCESS;


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


    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.

9 Years
Discussion Span
Last Post by cmsc_illiterate

That's not how you pass arrays. Remove the [], and you'll pass the address of it.


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!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.