c programming

Completado Publicado Aug 2, 2013 Pagado a la entrega
Completado Pagado a la entrega

Maritime and Technology Faculty

Technology Concepts and Processes

Activity 14

Purpose of this Activity

In the last session we encountered the idea that an array can have some value in the last location that can be used to tell where the end of the array (and hence the data) is. This value can be thought of as a terminator. The terminator used should not be a value that would turn up as normal data in the array.

With a numeric array that can only hold positive integers we used -1 as the terminator, but that was just our decision. The terminator chosen would have to be different if -1 could turn up in the data.

With an array of variables of type char (in other words an array of characters) we can use a special character as the terminator. This character is ‘\0’ – called NUL.

A char array terminated with NUL now becomes something special in the C language. It is called a string. There are a number of functions specifically designed to process strings.

A string could be initialised like this:

char str[] = {‘a’, ‘b’, ‘c’, ‘\0’};

However this is a little long winded and so it is easier to use:

char str = “abc”;

In this last case the compiler makes four locations of one byte each in memory and then puts the character a in location str[0], the character b in str[1] and so on, lastly it places the NUL in location str[3].

Intended outcomes

At the end of this session, you should be able to:

Declare and initialise a string

Write a string handling routine

Tasks

Read the Purpose of this Activity carefully. It may take several goes.

Write a program that initialises a char array as shown above. Write a loop to print this array out on the screen without the NUL character.

Modify the program so that it prints the array out in reverse order (HINT: have one loop that searches for the terminator – then use the count found in a second loop to count backwards from there back to zero)

Write a program that reads two strings from the keyboard one after another. The program should then compare each location in the two arrays to see if they contain the same value. If all of the values are the same right through the string the program should print out “SAME” otherwise it should print out “DIFFERENT”.

Looking back on the activity (Reflection)

Make sure that you put everything in your portfolio, record your participation and write briefly about what you have achieved.

Programación en C Programación en C++ PHP

Nº del proyecto: #4787897

Sobre el proyecto

5 propuestas Proyecto remoto Activo Aug 2, 2013

Adjudicado a:

bhatkiran

I can help you with this.

$20 USD en 3 días
(4 comentarios)
2.1

5 freelancers están ofertando un promedio de $19 por este trabajo

it2051229

Hi, I would like to do this project please. Let me know if you are interested so I can start. Thanks.

$20 USD en 0 días
(109 comentarios)
5.6
Schura

It is easy for me

$20 USD en 1 día
(30 comentarios)
4.9
kandamunlabs

This is very easy.

$16 USD en 2 días
(15 comentarios)
4.5
grigiq

Hi. Please see private message .

$20 USD en 0 días
(2 comentarios)
1.8