| | |
print the fields of a structure
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Mar 2007
Posts: 23
Reputation:
Solved Threads: 0
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 ?
or the field time in FIFA, or the field memory in word
How can i do this ?
C Syntax (Toggle Plain Text)
#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
c Syntax (Toggle Plain Text)
printf("name: %s\n", Doom3.name); printf("memory: %d\n", Doom3.memory); ...
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
-1
#3 14 Days Ago
'.' 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
~ssharish
'->' is the operator which you need when you dereference the struct pointer variable.
Like for an example
C Syntax (Toggle Plain Text)
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
"Any fool can know, point is to understand"
0
#4 14 Days Ago
consider the following:
C Syntax (Toggle Plain Text)
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...
•
•
Join Date: Dec 2009
Posts: 1
Reputation:
Solved Threads: 0
•
•
•
•
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 ?
C Syntax (Toggle Plain Text)
#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};
C Syntax (Toggle Plain Text)
printf("\n%s",proceso.Doom3.name);
Last edited by adatapost; 14 Days Ago at 2:28 am. Reason: Improved formatting.
![]() |
Similar Threads
- help with union and bit field structure. (C++)
- Why is qsort not initialised here!!?? (C)
- My 1st C++ program advice needed (C++)
- Error in mailer script (PHP)
- Need to create parse tree (Perl)
- Print 5 records per table row (see script) (Perl)
Other Threads in the C Forum
- Previous Thread: Flowchart help Please!
- Next Thread: Urgent Strings help!!!
Views: 3846 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for C
#include * append array arrays asterisks binarysearch calculate changingto char character cm command copyimagefile creafecopyofanytypeoffileinc database directory dynamic execv feet fgets file floatingpointvalidation fork forloop framework function functions getlogicaldrivestrin givemetehcodez grade graphics gtkwinlinux hacking histogram homework ide include incrementoperators input intmain() iso kernel keyboard kilometer km lazy license linked linkedlist linux list lists looping loopinsideloop. lowest matrix microsoft mqqueue number oddnumber odf openwebfoundation overwrite owf pause pdf performance pointer posix probleminc process program programming radix recursion recv recvblocked research reversing scripting segmentationfault sequential single socket socketprogramming spoonfeeding standard string student systemcall testing threads turboc unix urboc user variable whythiscodecausesegmentationfault windowsapi






