:: Student Platform :: Unofficial Forum ::

[prog] passing an array to a function

Getting Problems With Coursework Ect? Leave A Word Here

[prog] passing an array to a function

Postby kyu » Sat Mar 28, 2009 6:31 pm

bon mo conner mari basic ca, mais mo croir mo bizin enn revision express cause it's messing with me since some time already, ha!

so could anyone try to pinpoint what's wrong with the following?

Code: Select all
#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 10  //preprocessor constant used to define array size


void inparray(int *array)
/*function to input elements in array*/
{
    int i;
    for (i=0;(i!=MAXSIZE);i++)
    {
        printf("Please enter the element number %d ",i+1);
        scanf("%d",array[i]); //program crashes here
        printf("\n\n");
    }
}


int main()
{
    int array[MAXSIZE]={0,0,0,0,0,0,0,0,0,0};
    inparray(array);
}


anyone's got an idea why it crashes on input?


ps. euh displaying the array in another function works on the other hand.
d'apres role li pas p ecrire au bon endroit ca selon moi... mais bon :/
<subliminal>Kyu est grand, Kyu est fort, Kyu a toujours raison, meme quand il a tort. et pis zut, Kyu n'a jamais tort, voila! xD</subliminal>
User avatar
kyu
 
Posts: 103
Joined: Thu Feb 12, 2009 1:17 am
Location: in front of the pc (duh!)

Re: [prog] passing an array to a function

Postby kyu » Sat Mar 28, 2009 7:55 pm

ok ok got the solution finally lol
but got it by trying something weird, putting "&array[blabla]" as the param to scanf...
or, si zot pas conner normalement pas mette & devant array etant donner ki li deja enn pointer... so wtf is it required here? moi pas comprendre lol m'enfin, guess the original problem is solved though...
<subliminal>Kyu est grand, Kyu est fort, Kyu a toujours raison, meme quand il a tort. et pis zut, Kyu n'a jamais tort, voila! xD</subliminal>
User avatar
kyu
 
Posts: 103
Joined: Thu Feb 12, 2009 1:17 am
Location: in front of the pc (duh!)


Return to Help

Who is online

Users browsing this forum: No registered users and 1 guest