You are on page 1of 4

INTERNATIONAL UNIVERSITY

SCHOOL OF ELECTRICAL ENGINEERING

Programming For Engineers Laboratory

Course ID: EE058IU

Lab 6

Working with Characters and


Strings

Full name + Student ID: ……………………………………………………………………………………………………


…………………………………………………………………………………………………….
Class: ……………………………………………………………………………………………………………………………….
Group: …………………………………………………………………………………………………………………………….
Date: ………………………………………………………………………………………………………………………………

_____________________________________________________________________________________

1
INTERNATIONAL UNIVERSITY
SCHOOL OF ELECTRICAL ENGINEERING

I. Objectives

This laboratory exercise examines characters, details of string storage, and the operations
of string library functions within the C programming language.

Get familiar with the skill for working with character and string variables.

II. Pre-Lab Preparation

Read the theory carefully at home before coming to the class.

III. In-Lab Procedure

Exercise 1

Write a program in C to separate each single character from a string and find the total
number of characters in string without using String library

Output:

Input the string: School of EE

The characters of the string are:


S c h o o l o f E E
The number of characters in the string: 10

Exercise 2

Write a C program to find the number of times that a given character occurs in a sentence.

Output:

_____________________________________________________________________________________

2
INTERNATIONAL UNIVERSITY
SCHOOL OF ELECTRICAL ENGINEERING

Input the sentence: Welcome to C Lab


Input the character: e

The character 'e' occurs 2 time(s)

Exercise 3

Write a C program to convert the string to upper case by using function.

Output:

Enter a string: Mr. H is the best AI expert in HCM


Entered string in upper case is: "MR. H IS THE BEST AI EXPERT IN HCM"

Exercise 4

Write a C program to count the vowels and letters in free text given as standard input. Then
print out the number of occurrences of each of the vowels in the text, the total number of
letters, and each of the vowels as an integer percentage of the letter total.

Output:

Enter a word: Welcome to SEE HCMIU

The text entered is: Welcome to SEE HCMIU

=============================================

Numbers of characters:

a:0 e:4 i:1 o:2 u:1 rest:9

Percentages of total:

a:0.0% e:23.5% i:5.9% o:11.8% u:5.9% rest:52.9%

_____________________________________________________________________________________

3
INTERNATIONAL UNIVERSITY
SCHOOL OF ELECTRICAL ENGINEERING

Exercise 5

Write a C program to identify the total number of times a given word appears in a sentence.

Output:

Enter the word: the

Enter the string: the dog sat lazily in the shade of the tree

======================================

The word is 'the'.

The sentence is 'the dog sat lazily in the shade of the tree'.

The word 'the' occurs 3 time(s).

THE END

_____________________________________________________________________________________

You might also like