Hi I want to print in the screen only the fields of some of the data that is in the structure, Doom3 like: the name for example,
or the field time in FIFA, or the field memory in word
How can i do this ?

#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct proceso{
         char name[20];
         int  memory;
         int  time;
         int  files;
           };

struct proceso Doom3   ={"Doom3", 500, 4,5};
struct proceso Hades    ={"Hades", 100, 2,1};
struct proceso Word     ={"Word" ,  50, 1,1};
struct proceso FIFA       ={"FIFA" ,  10, 3,1};
struct proceso Doom2   ={"Doom2", 400, 5,2};



printf("\n ??????????

you have to print each field individually

printf("name: %s\n", Doom3.name);
printf("memory: %d\n", Doom3.memory);
...
Comments
lol... I cant understand this :P

'.' is the operatir which you are looking at.
'->' is the operator which you need when you dereference the struct pointer variable.

Like for an example

struct node
{
    int data;
}

struct node *d;
struct node d1;

printf("%d\n", d->data); // you could also use (*d).data here. The reason for this is operator precedences
printf("%d\n", d1.data);

~ssharish

Comments
2.5 YEARS late, what exactly have you added here? Nothing on-topic.

consider the following:

typedef struct 
{
   char name[20];
   int memory;
   int time;
   int files;
} proceso;        // proceso is a "type" of struct
                  // defined as having the above elements
 
proceso titulos[MAX_TITLES] = {       // titulos is an instance of proceso
   {"Doom3", 500, 4,5},               // declared as an array
   {"Hades", 100, 2,1},               // and containing the following values
   {"Word" , 50, 1,1},
   {"FIFA" , 10, 3,1},
   {"Doom2", 400, 5,2},
// ...
// question:  how many is "MAX_TITLES" ?
};

//....
// print fields like so

for (i=0; i<MAX_TITLES; i++)
{
   printf("title name: %s (%d MB)\n",titulos[i].name, titulos[i].memory);
}

// etc...

Hi I want to print in the screen only the fields of some of the data that is in the structure, Doom3 like: the name for example,
or the field time in FIFA, or the field memory in word
How can i do this ?

#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct proceso{
         char name[20];
         int  memory;
         int  time;
         int  files;
           };

struct proceso Doom3   ={"Doom3", 500, 4,5};
struct proceso Hades    ={"Hades", 100, 2,1};
struct proceso Word     ={"Word" ,  50, 1,1};
struct proceso FIFA       ={"FIFA" ,  10, 3,1};
struct proceso Doom2   ={"Doom2", 400, 5,2};
printf("\n%s",proceso.Doom3.name);

//try like this

Edited 7 Years Ago by __avd: Improved formatting.

Comments
awww!! shame shame :P
wrong
This article has been dead for over six months. Start a new discussion instead.