Functions and arrays

Posted by Ordo on Stack Overflow See other posts from Stack Overflow or by Ordo
Published on 2011-01-17T05:43:54Z Indexed on 2011/01/17 5:53 UTC
Read the original article Hit count: 188

Filed under:

Hello! My little program below shall take 5 numbers from the user, store them into an array of integers and use a function to print them out. Sincerly it doesn't work and nothing is printed out. I can't find a mistake, so i would be glad about any advice. Thanks.

#include <stdio.h>


void printarray(int intarray[], int n)

{
    int i;

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

int main ()

{
    const int n = 5;
    int temp = 0;
    int i;
    int intarray [n];
    char check;

    printf("Please type in your numbers!\n");

    for(i = 0; i < n; i ++)
    {
        printf("");
            scanf("%d", &temp);         
        intarray[i] = temp;

    }

    printf("Do you want to print them out? (yes/no): ");
        scanf("%c", &check);

        if (check == 'y')
            printarray(intarray, n);

    getchar();
    getchar();
    getchar();
    getchar();
    return 0;
}

© Stack Overflow or respective owner

Related posts about c