STRUCT – Definition And Access To Data

Complete example
We are going to make a complete example that uses tables (“arrays”), registers (“struct”) and that also manipulates chains.

The idea is going to be the following: We will create a program that can store data of up to 1000 files (computer files). For each file, you must save the following data: File name (max 40 letters), Size (in KB, number from 0 to 2,000,000,000). The program will show a menu that allows the user the following operations:

1- Add data of a new file
2- Show the names of all stored files
3- Show files that are more than a certain size (for example, 2000 KB).
4- See all the data of a certain file (from its name)
5- Quit the application (as we still do not know how to store the data, these will be lost).

It should not be difficult. Let’s look directly at one of the ways that could be raised and then discuss some of the improvements that could (even should) be made.

One option that we can take to solve this problem is to count the number of chips we have stored, and so we can add one to one. If we have 0 chips, we will have to store the next one (the first one) in position 0; if we have two chips, they will be 0 and 1, then we will add in position 2; In general, if we have “n” chips, we will add each new chip in the “n” position. On the other hand, to review all the chips, we will go from position 0 to n-1, doing something like

for (i = 0; i <= n-1; i ++) {… more orders …}
or something like

for (i = 0; i <n; i ++) {… more orders …}

You may also like...

1 Response

  1. 2017

    […] Previous story STRUCT – Definition And Access To Data […]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

error: Content is protected !!