Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
53 views

Built in Functions

Here is a C program that implements string manipulation functions with a menu: #include <stdio.h> #include <string.h> int main() { char username[10], string1[100], string2[100]; printf("Enter username: "); scanf("%s", username); if(strcmp(username, "user") == 0) { while(1) { int choice; printf("Menu:\n1) Count vowels and consonants\n2) Convert to uppercase\n3) Convert to lowercase\n4) Reverse string\n5) Concatenate strings\nEnter choice: "); scanf("%d", &choice); switch(

Uploaded by

Lhan Navida
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

Built in Functions

Here is a C program that implements string manipulation functions with a menu: #include <stdio.h> #include <string.h> int main() { char username[10], string1[100], string2[100]; printf("Enter username: "); scanf("%s", username); if(strcmp(username, "user") == 0) { while(1) { int choice; printf("Menu:\n1) Count vowels and consonants\n2) Convert to uppercase\n3) Convert to lowercase\n4) Reverse string\n5) Concatenate strings\nEnter choice: "); scanf("%d", &choice); switch(

Uploaded by

Lhan Navida
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Built-in Functions

(Math and String)


• Part 1: Discussion (Midterm Hands-on Exam Solution)
• Part 2: Discussion (String Built-in Function in C )
• Part 3: Learning Task
• Part 4: Hands-on
Objectives

• At the end of the discussion, the students are expected to:


– Identify the commonly used math and string functions in C;
– Solve programming problems using math and string functions;
– Appreciate the practical applications of math and string
functions in programming;
– Trace and correct the encountered syntax and logic errors in a
written program.
Functions

• Functions are group or set of programming statement that


together performs a task.
– Functions are classified as:
• Built-in functions- these are predefined functions which
statements/instructions are stored/built in a relevant header file.
– Examples: Math and String Function
• Programmer defined- these are functions which statements/instructions
are defined or created by the programmer.
Math Functions

• These are functions that performs built-in mathematical


operations;
• Header file math.h
– ceil() computes the nearest integer greater than the argument passed.
– floor() calculates the nearest integer less than the argument passed
– cbrt() computes the cube root of a number
– log10() computes the base 10 logarithm of an argument
– pow() computes the power of a number
– sqrt() computes the square root of a number
Example
Learning Task 11

• Create a C program using math functions that will display


an output as shown below:
String Function

• These functions include built-in instructions to speed up the manipulation of string in C


programming language;
• There are more than 18 built-in string function but only four of them are used frequently;
• Header file: string.h
• Frequently used string built in functions:
– strlen() as its name suggest, this function is made to calculate the length of the string;
– strcpy() this function is used to copy contents of one string to another string;
– strcat() this function is used to concatenate (combine) two strings.
– strcmp() this function is used to compare two strings. This function returns 0 if the strings are
identical and returns the difference of ASCII values when a mismatch occurs.
– strrev() this function is used to reverse the characters in a given string
– strlwr() this function is used to convert the given string to lowercase
– strupr() this function is used to convert the given string to uppercase
Example: strlen()
Example: strcpy()
Example: strcat()
Example: strcmp()
Example:
strrev(),strlwr(),strupr()
Learning Task 11

• Write a C program that will serve as a string manipulation program that will
include the following menus:
(1) Count the Vowels and Consonants
(2) Convert to Uppercase
(3) Convert to Lowercase
(4) Reverse String
(5) Concatenate String

The end user should choose what action to do based from the options in the menu. Invalid
inputs should not be accepted and will cause exit from the program.
Before the user will be able to access the program, the end user should input first the valid
username, otherwise access to the system will be denied and will cause exit from the
program.

You might also like