0% found this document useful (0 votes)
11 views1 page

124 LabWork-07

maqya

Uploaded by

isheanesundewere
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views1 page

124 LabWork-07

maqya

Uploaded by

isheanesundewere
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

COMP124 Computer Programming

2022-23 Spring
Laboratory Work No. 7
Arrays II

An array is a sequence of data items that are of the same type, that can be indexed, and that are stored contiguously. Typically,
an array is called a data structure used to represent a large number of homogeneous values. The elements of an array are accessed
by the use of subscripts. Subscripts start from zero and runs until less than the size of the array. Arrays of all types are possible,
including multi-dimensional arrays. Strings are just arrays of characters terminated by a special character called the null character.
A typical array declaration allocates memory starting from a base address. The array name is in effect a constant pointer to this
memory address.

a) Write a complete C program that demonstrates the usage of character strings. The program should declare an empty
character array of specific size, and then ask user to enter a string to be stored in the array using a scanf function. The
program should finally display the string entered to the screen for checking if the characters are correctly stored or not.

 Develop a user-defined function executing the steps needed for prompting the user by a simple message like “Enter a
string:” and for entering the string. Keep in mind that arrays are passed-by-reference!

b) Improve the program written in part (a) by calculating the string length and displaying it to the screen.

 Develop a user-defined function for calculating the string length.


 Show the usage of this function in the program.

c) Improve the program written in part (b) by making a copy of the string entered to another empty character array inside
the main function.

 The resulting copied string shall be displayed to the screen for checking purpose!
 Develop a user-defined function doing the string copying process.
 Show the usage of this function in the program.

d) [if time allows] Improve the program written in part (c) by letting the user to specify two strings to be concatenated into
a third one.

 Try concatenation process inside the main function first!


 Develop a user-defined function doing the string concatenation process.
 Show the usage of this function in the program.

1/1

You might also like