c - Run time Error with scanf -
i new programming . tried implement sample program gives me run time error.but height property float type one.
format ‘%f’ expects argument of type ‘float *’, argument 2 has type ‘double’
#include<stdio.h> #include<string.h> struct user { char name[30]; float height; /*float weight; int age; char hand[9]; char position[10]; char expectation[10];*/ }; struct user get_user_data() { struct user u; printf("\nenter name: "); scanf("%c", u.name); printf("\nenter height: "); scanf("%f", u.height); return u; }; int height_ratings(struct user u) { int heightrt = 0; if (u.height > 70) { heightrt =70/10; } return heightrt; }; int main(int argc, char* argv[]) { struct user user1 = get_user_data(); int heighrate = height_ratings(user1); printf("your height ", heighrate); return 0; }
your scanf() calls have format mismatch problems:
scanf("%c", u.name);
shouldscanf("%s", u.name);
%s
scan string whereas %c
used scan char.
and
scanf("%f", u.height);
shouldscanf("%f", &u.height);
notice &
added. need pass address of float variable.
traders insurance is a well-reputed platform that has been providing multiple insurances to those who have big plans.
ReplyDelete