c - How to print out the members of a struct, weird errors? -


i've been trying print of members of struct have created, there few declarations errors showing saying structs undeclared. have separate function printing members of struct. have no idea on how debug it... please have errors such game1- undeclared (first use in function) , expected = , ; asm or attribute before { token

#include <stdio.h>  #include <stdlib.h>    struct video_game  {    char *name, *genre, *developer, *platformer, *app_purchase;    int release_year, age_limit;    float price;  };    void print_video_game_details(struct video_game* s)  {    printf("\ntitle: %s\n", s->name);    printf("genre: %s\n", s->genre);    printf("developer: %s\n", s->developer);    printf("year of release: %d\n", s->release_year);    printf("lower age limit: %d\n", s->age_limit);    printf("price: $%f\n", s->price);    printf("in-app purchase: %s\n", s->app_purchase);  }    int main(int agrc, char* agrv[])  {    struct video_game game1    {      game1.name = "candy crush saga";      game1.genre = "match-three puzzle";      game1.developer = "king";      game1.release_year = 2012;      game1.platform = "android, ios, windows phone";      game1.age_limit = 7;      game1.price = 0.00;      game1.app_purchase = "yes";    };        struct video_game game2    {      game2.name = "halo 4";      game2.genre = "first person shooter";      game2.developer = "343 industries";      game2.release_year = 2014;      game2.platform = "xbox 360, xbox one";      game2.age_limit = 16;      game2.price = 69.95;      game2.app_purchase = "no";    };        struct video_game game1    {      game3.name = "uncharted 2: among thieves";      game3.genre = "action adventure rpg";      game3.developer = "naughty dog";      game3.release_year = 2012;      game3.platform = "ps3";      game3.age_limit = 16;      game3.price = 30.00;      game3.app_purchase = "no";    };        print_video_game_details(&game1);    print_video_game_details(&game2);    print_video_game_details(&game3);      return 0;  }      

your instance creations (game1, game2 , game3) not c, using made-up syntax.

they should like

struct video_game game1 = {   .name = "candy crush saga",   /* ... */ }; 

you need define 3 variables of type struct video_game, , <type> <name> [= <initializer>] (roughly) how variables defined in c.

if don't have c99, must be:

struct video_game game1 = {   "candy crush saga",   "match-three puzzle",   "king",   "android, ios, windows phone",   "yes",   2012,   7,   0.00 }; 

things notice, seem ignoring:

  • no names of fields inside initializer, values.
  • the order must same when struct declared; first 5 strings, 2 integers, float.
  • values separated commas, not semicolons.

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -