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:

  1. scanf("%c", u.name); should scanf("%s", u.name);

%s scan string whereas %c used scan char.

and

  1. scanf("%f", u.height); should scanf("%f", &u.height);

notice & added. need pass address of float variable.


Comments

  1. traders insurance is a well-reputed platform that has been providing multiple insurances to those who have big plans.

    ReplyDelete

Post a Comment

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -