1 / 17

EEL 2880 Group #4

Erick Barrera Manuel Costa Marbelys Iglesias Adrian Martin Osvaldo Reyes Emmanuel Stimphil Elie Victor. EEL 2880 Group #4. Step thru Array of Structures. General Objectives: Explain and provide examples of how to pass through an array of structures using pointers

felix
Download Presentation

EEL 2880 Group #4

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Erick Barrera Manuel Costa Marbelys Iglesias Adrian Martin Osvaldo Reyes Emmanuel Stimphil Elie Victor EEL 2880 Group #4

  2. Step thru Array of Structures General Objectives: • Explain and provide examples of how to pass through an array of structures using pointers • Develop elements required to accomplish this • Visually illustrate the process through the use of a Block Diagram/Flow Chart • Describe how the program operates both overall and in depth • Provide alternate example

  3. Introduction • What is a structure? • Structures, commonly referred to as aggregates, are collections of related variables under one name. • Structures may contain variables of many different data types, unlike arrays which can only hold elements of the same data type. • Pointers and structures facilitate the formation of more complex data structures such as linked lists, queues, stacks, and trees.

  4. Structures That Contain Arrays You can define a structure that contains one or more arrays as members. The array can be of any C data type (int, char, and so on). For example, the statements struct data{ int x[4]; char y[10]; }; struct data record;

  5. Structures That Contain Arrays You access individual elements of arrays that are structure members using a combination of the member operator and array subscripts: record.x[2] = 100; record.y[1] = ‘x’; Character arrays are most frequently used to store strings. Also, the name of an array, without brackets, is a pointer to the array. Because this holds true for arrays that are structure members, the expression record.v puts(record.v);

  6. A structure that contains array

  7. /* Demonstratessteppingthroughanarray of structures */ /* using pointer notation. */ #include <stdio.h> #define MAX 4 Compile Library: Standard Input/Output Library /* Define a structure, then declare and initialize */ /* anarray of 4 structures. */ structpart { intnumber; charname[10]; }; Structure is Declared and Created: one character array named “name” with 10 characters max. /* Declare a pointer totypepart, and a counter variable. */ structpart data[MAX] = { {1, "Smith"}, {2, "Jones"}, {3, "Adams"}, {4, "Wilson"} }; Initialize /* Declare a pointer totypepart, and a counter variable. */ structpart *p_part; intcount; Give Structure a name: Gives a place to store any data given by user and a way to reference it. intmain(void) { /* Initializethe pointer tothefirstarrayelement. */ p_part = data; /* Loopthroughthearray, incrementingthe pointer */ /* witheachiteration. */ for (count = 0; count < MAX; count++) { printf("\nAtaddress %p: %d %s", p_part, p_part->number, p_part->name); p_part++; } } Main Function

  8. Block Diagram

  9. Block Diagram (continued)

  10. Structured Flow Chart

  11. Entire Code

  12. Program Output

  13. Alternative Example Code

  14. Alternate Example Output

  15. Lessons Learned • How to use pointers through an array of structures • Provide examples of how they can be used • The relationship between pointers and arrays • The step-by-step procedure of how the program works

  16. Research • www.google.com • C-How to Program 5th & 6th Edition, Deitel& Deitel

  17. Thank you. The End

More Related