0

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
4
Contributors
4
Replies
23
Views
3 Years
Discussion Span
Last Post by deceptikon
Featured Replies
  • 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`. Read More

0

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 by rubberman

0

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

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

Edited by Ancient Dragon

0

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;
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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.