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

Recommended Answers

All 4 Replies

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...

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

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.