Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

can someone explain this to me?

Posted on 2007-11-19
9
Medium Priority
?
313 Views
Last Modified: 2010-04-15
hi experts.
i have these codes for C programming....
now i'm having trouble understanding the codes...
could someone please explain why, how and what these codes r being used?
thnx

#include <stdio.h>

 #define MAX 4

 /* Define a structure, then declare and initialize */
 /* an array of 4 structures. */

 struct part {
     int number;
     char name[10];
 };
 /* Declare a pointer to type part, and a counter variable. */


struct part data[MAX] =
                {
                    {1, "Smith"},
                    {2, "Jones"},
                    {3, "Adams"},
                    {4, "Wilson"}
                };

 /* Declare a pointer to type part, and a counter variable. */



 struct part *p_part;
 int count;

 int main(void)
 {
     /* Initialize the pointer to the first array element. */

     p_part = data;

     /* Loop through the array, incrementing the pointer */
     /* with each iteration. */

     for (count = 0; count < MAX; count++)
     {
         printf("\nAt address %p: %d %s", p_part, p_part->number,
                 p_part->name);
         p_part++;
     }

 }
0
Comment
Question by:tsburt
9 Comments
 
LVL 85

Expert Comment

by:ozo
ID: 20316973
What do you need explained?
Are the comments or the  C documentation for something confusing?
0
 
LVL 1

Author Comment

by:tsburt
ID: 20317010
yea i ahve a diff time understanding why these certain codes r used. i basically just started learnign C and if someone could explain line by line why this is need and what it does . i would be greatfull
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 53

Accepted Solution

by:
Infinity08 earned 500 total points
ID: 20318173
>> i basically just started learnign C

Then don't jump into the deep immediately. Get some C basics first (like the link PCableGuy listed).

This one looks pretty good :

       http://www.physics.drexel.edu/courses/CompPhys/General/C_basics/c_tutorial.html

After you've read and understood that (try everything out using your compiler while you're reading), you should be able to understand what the code you posted is doing. If you still have problems then, then we'll be happy to help you :)
0
 
LVL 1

Author Comment

by:tsburt
ID: 20325692
so basically what the define max 4 is doing is defining that there r 4 data : smith , jones, adams, wilson.
but what does the
struct part {
     int number;
     char name[10];

do is this statement?
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 20326128
>> do is this statement?

No, that's a struct definition. It defines a new datatype that is a grouping of an int and a 10 character array.

Once it's defined, you can start using it, ie. make an instance called myPart :

        struct part myPart;

then set some values in myPart :

        myPart.number = 5;
        strcpy(myPart.name, "jack");

So, now myPart has number 5, and name "jack".

A struct is a convenient way of grouping data of different types together.
0
 
LVL 1

Author Comment

by:tsburt
ID: 20326187
ok i get it ..thnx infinity.
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 20326204
Do you understand the rest of the code ?
0
 
LVL 1

Author Comment

by:tsburt
ID: 20348338
yes...new struc p_part = to the data
refering the p_part to teh info from data
and than print
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question