c programming

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


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.

Skills: C Programming, C++ Programming, PHP

See more: what programming language is this, what programming language, what is programming language, what is in c programming, what is c programming used for, what is c# programming, what is c programming, what is a string in programming, what is a programming language, what is an array in programming, what is a loop in programming, what are integers used for, variables in programming, the c# programming language, the c programming language, the c programming, the c language, strings in c programming, string programming, string in c programming, string c programming, reverse thought, reflection programming, purpose of use case, programming words

About the Employer:
( 57 reviews ) albama, United Kingdom

Project ID: #4787897

Awarded to:


I can help you with this.

$20 USD in 3 days
(4 Reviews)

5 freelancers are bidding on average $19 for this job


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

$20 USD in 0 days
(109 Reviews)

It is easy for me

$20 USD in 1 day
(30 Reviews)

This is very easy.

$16 USD in 2 days
(15 Reviews)

Hi. Please see private message .

$20 USD in 0 days
(2 Reviews)