Solved

can someone explain this to me?

Posted on 2007-11-19
9
298 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 84

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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 53

Accepted Solution

by:
Infinity08 earned 125 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

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.

Question has a verified solution.

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

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
Suggested Courses

626 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