scanf_s not enough arguments passed for format string(Visual Studio)

8.5k Views Asked by At

The program showing error as title. What's wrong on scanf_s function? Any idea? Thanks in advance.

int main()
    {
        struct Students
        {
            char name[10];
            int  snum;
            float  point;
        }st[5];

int i;
for(i=0;i<5;i++)
{
    printf("-- Student Info --\n-");

    printf("Enter Your Name: ");
    scanf_s("%s",st[i].name);

    printf("\nEnter Your Number: ");
    scanf_s("%d",&st[i].snum);
}

return 0;
}
1

There are 1 best solutions below

0
On

This type of error usually comes when the compiler detects mismatch between number of arguments required to satisfy placeholders in format string and number of arguments supplied .

This was a new warning supplied in Visual Studio 2015 onwards . So for your code to work correctly you need to supply two arguments one is the address one and second one which is extra is the sizeof(variable) placeholder .

scanf_s("%s", &string, sizeof(string));

This would let the code work correctly .