UC3M

Telematic/Audiovisual Syst./Communication Syst. Engineering

Systems Architecture

September 2017 - January 2018

C pointers

Exercises

 

And get ready, 
cause this s--t is about to get heavy

 
  --Eminem

1.  Using pointers in C

Work Plan

  1. Prepare the development environment to create, compile and execute short programs.

  2. Read the chapter about pointers (40 minutes). Write all the unclear points and clarify them either with the professor or posting them in the course forum.

  3. Solve the first ten exercises in the chapter. If after solving them you sense you have unclear concepts about pointers, go to office hours with the professor. If you sense that the concepts are clear, solve the remaining problems.

How long did this activity take you? mins.

2.  Managing cells in your mobile phone

Work Plan

A mobile application needs to store the cells that are within range at each time. The number of cells is unknown and changes depending on the device position. Each cell has a unique identifier (positive integer) and a level of signal quality (number between 0 and 100). At each time, the application denotes one of the cells as the current (the one offering the highest signal quality). Every certain time, this information is updated depending on the signal quality field.

The following two functions are already implemented in the application:

  • ... new_cell(). Returns a pointer to a new cell structure. The result type is the data structure to store the cell information.

  • void remove_cell(...). Function opposite to the previous one, receives a pointer to a cell data structure and gets rid off it. You must call this function to make the data structure disappear.

You have to rite the following code portions:

  • Define the data structure to store the cell data and declaration of the variables required to stored the application data.

  • void fill_fields(...). Function that assigns the values given as parameters to the fields of a structure pointed to by an additional parameter. Decide first the parameters received by the function and then the code.

  • void update_current(...). Function that assigns as current the one with the higher quality signal.

  • What change would you make in the definition of the data structure to store the data in a circular form (that is, they are ordered as a circle)?

You may following the steps:

  1. How will you represent the set of cells? Do you know in advance how many cells you have to manipulate?

  2. Define the data structures required to store the set of cells. How do you distinguish the actual cell?

  3. What do you think it should be the prototype of the function new_cell?

  4. Define the prototype of the fill_fields function. Write its code.

  5. Implement the update_current function.

  6. What is the meaning of a circular structure and how to implement it in C?

How long did this activity take you? mins.