I want to add numbers to an array using scanf
What did i do wrong? it says expected an expression on the first { in front of i inside the scanf...

void addScores(int a[],int *counter){
    int i=0;
    printf("please enter your score..");
    scanf_s("%i", a[*c] = {i});
}//end add scores

What is the 'c' variable? Do you mean 'counter'? IE, your code is not functional. Also, if you mean 'counter' instead of 'c', then you are setting a[*counter] to 0, so the value scanned would be set to 0, before being set to what was found int the stdin stream...

Edited 3 Years Ago by rubberman

scanf_s("%i", &a[*counter]);

scanf() expects the first parameter to be a pointer, so you have to add the pointer operator &.

Edited 3 Years Ago by Ancient Dragon

Thanks guys i ment to put c i just changed it to counter so you guys knew what it was
I changed it to this and it works :)
(dont worry there is other important factors going on in main

void addScores(int a[],int *c){
    int i=0;
    printf("please enter your score..");
    scanf_s("%i", &a[*c]);
    *c = *c + 1;

i ment to put c i just changed it to counter so you guys knew what it was

That's a hint that it should be counter in the first place rather than c.

This question has already been answered. Start a new discussion instead.