Reputation: 43
I have the following code:
#include <stdio.h>
float a; //Initialize variables
char b;
int c;
char d;
int main(void)
{
printf("Enter float: ");
scanf("%4.2f", &a);
printf("%4.2f", a);
//printf("Enter character:\n");
//printf("Enter 4-digit integer: \n");
//printf("Enter character:\n");
return 0;
}
However I get the following errors when compiling:
1.)
scanf
:unknown field type character '.' in format specifier2.)
scanf
: too many arguments passed for format string
Can anyone explain what the issue in my code is?
Thank you!
Upvotes: 1
Views: 4200
Reputation: 1754
scanf("%f",&a)
does not take format specifier.
As mentioned in comments Visual Studio treat this warning as error. So either use
scanf_s("%f",&a);
or go into settings and disable this warning as mentioned in this post Why does Visual Studio 2013 error on C4996?
Upvotes: 4
Reputation:
You should not format the input. So just use %f
as a first argument of scanf
scanf("%f", &a);
Upvotes: 3