EKT150 INTRODUCTION TO COMPUTER PROGRAMMING

Slides:



Advertisements
Similar presentations
Problem Solving & Program Design in C
Advertisements

C Characters & Strings Character Review Character Handling Library Initialization String Conversion Functions String Handling Library Standard Input/Output.
 2003 Prentice Hall, Inc. All rights reserved Fundamentals of Characters and Strings Character constant –Integer value represented as character.
Strings.
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
 2000 Prentice Hall, Inc. All rights reserved Fundamentals of Strings and Characters String declarations –Declare as a character array or a variable.
ECE Application Programming Instructor: Dr. Michael Geiger Spring 2012 Lecture 31: PE5.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Characters and Strings.
Current Assignments Homework 5 will be available tomorrow and is due on Sunday. Arrays and Pointers Project 2 due tonight by midnight. Exam 2 on Monday.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 8 - Characters and Strings Outline 8.1Introduction 8.2Fundamentals of Strings and Characters 8.3Character.
Chapter 8 Characters and Strings Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Fundamentals of Strings and Characters Characters.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 8 - Characters and Strings Outline 8.1Introduction.
Week 7 – String. Outline Passing Array to Function Print the Array How Arrays are passed in a function call Introduction to Strings String Type Character.
Data Structure and C Part-6. Naming a Function Any valid variable-name can be given to the user-defined function. The main program itself is considered.
 2007 Pearson Education, Inc. All rights reserved C Characters and Strings.
1. An array is a collection of a fixed number of components wherein all of the components are of the same type Example: Suppose that there is a list of.
Strings in C. Strings are Character Arrays Strings in C are simply arrays of characters. – Example:char s [10]; This is a ten (10) element array that.
The character data type char
EPSII 59:006 Spring Introduction Fundamentals of Strings and Characters Character Handling Library String Conversion Functions Standard Input/Output.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 8 - Characters and Strings Outline 8.1Introduction 8.2Fundamentals of Strings and Characters 8.3Character.
STRING Dong-Chul Kim BioMeCIS UTA 10/7/
Arrays II (Strings). Data types in C Integer : int i; Double: double x; Float: float y; Character: char ch; char cha[10], chb[]={‘h’,’e’,’l’,’l’,’o’};
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI C-Style Strings Strings and String Functions Dale Roberts, Lecturer.
CSC141- Introduction to Computer programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture – 21 Thanks for Lecture Slides:
1 Information Representation in Computer Lecture Nine.
 2003 Prentice Hall, Inc. All rights reserved. 11 Fundamentals of Characters and Strings Character constant –Integer value of a character –Single quotes.
String Array (Multidimensional Arrays) 1. A string array is a multidimensional array of strings. It is declared in the following syntax: char variable_name[No_of_strings][size_of_each_string];
UniMAP SEM I - 09/10EKT 120 Computer Programming1 Lecture 8 – Arrays (2) & Strings.
Chapter 8 Characters and Strings. Objectives In this chapter, you will learn: –To be able to use the functions of the character handling library ( ctype).
UniMAP SEM I - 10/11EKT 120 Computer Programming1 Lecture 8 – Arrays (2) and Strings.
C++ Programming Lecture 19 Strings The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI N305 Characters and Strings Functions.
1 Arrays and Pointers The name of an array is a pointer constant to the first element. Because the array’s name is a pointer constant, its value cannot.
1 Chapter 8 - Characters and Strings Outline 8.1Introduction 8.2Fundamentals of Strings and Characters 8.3Character Handling Library 8.4String Conversion.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 230 Characters and Strings Dale Roberts, Lecturer Computer Science,
Principles of Programming - NI Chapter 10: Character & String : In this chapter, you’ll learn about; Fundamentals of Strings and Characters The difference.
String in C++. 2 Using Strings in C++ Programs String library or provides functions to: - manipulate strings - compare strings - search strings ASCII.
1 Chapter 8 – Character Arrays and Strings Outline 8.1Introduction 8.2Declaring and Initializing String 8.3Input/output of strings 8.4String-handling Functions.
EC-111 Algorithms & Computing Lecture #10 Instructor: Jahan Zeb Department of Computer Engineering (DCE) College of E&ME NUST.
Introduction Programs which manipulate character data don’t usually just deal with single characters, but instead with collections of them (e.g. words,
C Characters and Strings
Strings CSCI 112: Programming in C.
INC 161 , CPE 100 Computer Programming
Pointers & Arrays 1-d arrays & pointers 2-d arrays & pointers.
C Characters and Strings
Fundamentals of Characters and Strings
EKT120 : Computer Programming
Programming Languages -1 (Introduction to C) strings
Module 2 Arrays and strings – example programs.
Strings A string is a sequence of characters treated as a group
Computer Science 210 Computer Organization
Arrays in C.
Chapter 8 - Characters and Strings
ASCII Character Codes nul soh stx etx eot 1 lf vt ff cr so
Week 9 – Lesson 1 Arrays – Character Strings
EKT120: Computer Programming
String in C++.
Number Systems Lecture 2.
C-strings In general, a string is a series of characters treated as a unit. Practically all string implementations treat a string as a variable-length.
Chapter 2 Array and String Visit to more Learning Resources.
CPS120: Introduction to Computer Science
C Strings Prabhat Kumar Padhy
EECE.2160 ECE Application Programming
Strings Adapted from Dr. Mary Eberlein, UT Austin.
C++ Programming Lecture 20 Strings
Strings in C Array of characters is called a string.
Lecture 19: Working with strings
Characters and Strings Functions
C Characters and Strings
Presentation transcript:

EKT150 INTRODUCTION TO COMPUTER PROGRAMMING Array (String) Part II Dr. Nur Hafizah Ghazali hafizahghazali@unimap.edu.my

Recaps… What is Array? (Example) Multiple instance with the same data type could be declared as an array: int aiNum[5]; aiNum[0]=5; aiNum[1]=10; aiNum[2]=15; aiNum[3]=20; aiNum[4]=25; Declaration aiNum Assign 5 to element with index number 0 5 10 15 20 25 aiNum[0] aiNum[1] aiNum[2] aiNum[3] aiNum[4] Element aiNum[1] has index 1 and value 10 int is the data type of the array 5 in squared bracket is the number of components/elements in the array Elements are referred to an index number Index number starts with 0

Recaps…. Example : 2-Dimensional Array int aiValue[4][2]; //declaration aiValue[2][1]=5;//assignment of value Column 0 1 1 2 3 aiValue[0][0] aiValue[0][1] aiValue[1][0] aiValue[1][1] aiValue[2][0] aiValue[2][1] aiValue[3][0] aiValue[3][1] Row

Outline Introduction to Strings Declaration of Strings Fundamentals of Strings & Characters Initialization of Strings Assigning Values to Strings Character and String Manipulations Strings Conversion Functions ASCII Table

What is a String? A string is a series of characters treated as a single unit. Also known as character array Strings can be treated as array of type char used to store names of people, places, or anything that involves a combination of letters. A string may include letters, digits and various special characters such as +, -, *, ? and $. String literals, or string constants, in C are written in double quotation marks ( “ ” ) as follows: Example: “John Doe” (a name) “99999 Main Street” (a street address) “Kangar, Perlis” (a city and a state) “(012) 123-8755” (a telephone number)

What is a String? The data type string is a programmer-defined and is not part of the C language A string with no characters is called a null or empty string. “ ” is the empty string. Every character in a string has a relative position in the string. The position of the first character is 0, position of the second is 1, and so on. The length of a string is the number of character in it. of a string is the address of its first character.

Example String Position of a Character Length of the String in the String “William Jacob” Position of ‘W’ is 0 13 Position of the first ‘i’ is 1 Position of ‘ ’ (the space) is 7 Position of ‘J’ is 8 Position of ‘b’ is 12 “Mickey” Position of ‘M’ is 0 6 Position of ‘i’ is 1 Position of ‘c’ is 2 Position of ‘k’ is 3 Position of ‘e’ is 4 Position of ‘y’ is 5

Declaration of Strings Declaration of string/character array char variable_name[length]; An example of declaration of an array (or string of characters): char name[10]; //declaration can use to store “William”, “John Doe” etc and all strings that shorter than defined length It is not necessary that this max size of 10 characters should at all the times fully used The last value in the string will be a null character (‘\0’). char name[10]; can store a string up to 10 characters long, and may visualize it as below name

Declaration of Strings (cont…) name is an array of 10 elements of type char, could be represented by storing the strings of characters, e.g. “William” and “John Doe” in the following way: name W i l l i a m \0 to indicate end of string indefinite values J o h n D o e \0

Declaration of Strings (cont…) Also can be declared as a character array or a variable of type char * char name[] = “William"; char *name = “William";

Formatted Input/ Output Use scanf scanf("%s", name); Copies input into name[] Does not need & (because a string is a pointer) Remember to leave room in the array for the null character ('\0’) Formatted output Use printf printf(“%s”,name);

Example : Input and Output of String Input and output characters using scanf() and printf() Example program: #include<stdio.h> int main() { char name[30]; printf("Enter name: "); scanf(“%s”,name); //read string from user printf(“Hi %s\n“,name); //display string return 0; }

Initialization of String Similar to array, but each character is enclosed in ‘ ’ or “ ”. Example: char newString[]={‘W’, ‘e’, ‘l’, ‘c’, ‘o’, ‘m’, ‘e’, ‘\0’}; char newString[]= “Welcome”; ‘\0’ is automatically inserted The difference is that single quotes (‘) are used to specify single character constants and null character must be added at the end of the sentence. char newString[]= {‘W’,‘e’,‘l’,‘c’,‘o’,‘m’,‘e’,‘\0’}; Single quotes – null char must be added

Initialization of String On the other hand, double quotes (“) are constant that specify sequence of characters and always have a null character (‘\0’) automatically inserted at the end.   char newString[] = “Welcome”; Double quotes – null char automatically inserted

Initialization of String (cont…) The examples below are NOT VALID for string / characters array. newString = “Welcome”; //no [] and data type newString [] =“Welcome”; //no data type newString = {‘W’,‘e’,‘l’,‘c’,‘o’,‘m’,‘e’,‘\0’}; //no [] and data type

Assigning Values to String The left hand side value of an assignation can only be array items and not the entire array, a possible way to assign a string of characters to an array of char can be shown as: newString[0] = ‘W’; newString[1] = ‘e’; newString[2] = ‘l’; newString[3] = ‘c’; newString[4] = ‘o’; newString[5] = ‘m’; newString[6] = ‘e’; newString[7] = ‘\0’;

Character and String Manipulation A program may need to verify/perform, e.g. Calculation of the string size Copy one string to another Appends one string to another Built-in functions available – makes it easier. Standard input/output library <stdio.h> General utilities library <stdlib.h> Character handling library <ctype.h> String handling library <string.h>

Example 1.1: Input and Output of String without using Built-in Function Input and output characters using scanf() and printf() function from <stdio.h> Example program: #include<stdio.h> int main() { char name[30]; printf("Enter name: "); scanf(“%s”,name); //Function to read string from user printf(“Hi "); printf(“%s\n”,name); //Function to display string return 0; }

Example 1.1: Input and Output of String without using Built-in Function Input and output characters using scanf() and printf() function from <stdio.h> Example program: #include<stdio.h> int main() { char name[30]; printf("Enter name: "); scanf(“%s”,name); //Function to read string from user printf(“Hi "); printf(“%s\n”,name); //Function to display string return 0; } Enter name : John Hi John

Example 1.2: Input and Output of String using Built-in Function Input and output characters using gets() puts() function from <stdio.h> Example program: #include<stdio.h> int main() { char name[30]; printf("Enter name: "); gets(name); //Function to read string from user printf(“Hi "); puts(name); //Function to display string return 0; }

Example 1.2: Input and Output of String using Built-in Function Input and output characters using gets() puts() function from <stdio.h> Example program: #include<stdio.h> int main() { char name[30]; printf("Enter name: "); gets(name); //Function to read string from user printf(“Hi "); puts(name); //Function to display string return 0; } Enter name : John Hi John

Example 2.1: Input and Output of String without using Build-in Function Input and output for array of strings Example program: #include<stdio.h> int main() { char name[3][30]; printf("Enter 3 names:\n"); for(i=0;i<3;i++) scanf(“%s”,name[i]);//Function to read string from user printf(“\nName Entered:\n”); printf(“%s\n”,name[i]); //Function to display string return 0; }

Example 2.1: Input and Output of String without using Build-in Function Input and output for array of strings Example program: #include<stdio.h> int main() { char name[3][30]; printf("Enter 3 names:\n"); for(i=0;i<3;i++) scanf(“%s”,name[i]);//Function to read string from user printf(“\nName Entered:\n”); printf(“%s\n”,name[i]); //Function to display string return 0; } Enter 3 names: Michael John Sarah Names Entered:

Example 2.2: Input and Output of String using Build-in Function Input and output of array of strings using gets() puts() function from <stdio.h> Example program: #include<stdio.h> int main() { char name[3][30]; printf("Enter 3 names:\n"); for(i=0;i<3;i++) gets(name[i]); //Function to read string from user printf(“\nName Entered:\n”); puts(name[i]); //Function to display string return 0; }

Example 2.2: Input and Output of String using Build-in Function Input and output of array of strings using gets() puts() function from <stdio.h> Example program: #include<stdio.h> int main() { char name[3][30]; printf("Enter 3 names:\n"); for(i=0;i<3;i++) gets(name[i]); //Function to read string from user printf(“\nName Entered:\n”); puts(name[i]); //Function to display string return 0; } Enter 3 names: Michael John Sarah Names Entered:

Example 3.1: Calculation of String Size without Build-in Function Calculation of string size by measuring number of elements from the string Example program: #include <stdio.h> int main() { char newString1[] = {'W','e','l','c','o','m','e','\0'}; char newString2[] = “Bye Bye"; int i,length_newString1=0,length_newString2=0; for(i=0;newString1[i]!='\0';i++) length_newString1++; for(i=0;newString2[i]!='\0';i++) length_newString2++; //size of string Welcome printf ("Size of ‘%s’ is %d\n", newString1,length_newString1); //size of string Good Bye printf ("\nSize of ‘%s’ is %d\n",newString2, length_newString2); return 0; }

Example 3.1: Calculation of String Size without Build-in Function Calculation of string size by measuring number of elements from the string Example program: #include <stdio.h> int main() { char newString1[] = {'W','e','l','c','o','m','e','\0'}; char newString2[] = “Bye Bye"; int i,length_newString1=0,length_newString2=0; for(i=0;newString1[i]!='\0';i++) length_newString1++; for(i=0;newString2[i]!='\0';i++) length_newString2++; //size of string Welcome printf ("Size of ‘%s’ is %d\n", newString1,length_newString1); //size of string Good Bye printf ("\nSize of ‘%s’ is %d\n",newString2, length_newString2); return 0; } Size of `Welcome’ is 7 Size of `Bye Bye’ is 8

Example 3.2: Calculation of String Size using Build-in Function Calculation of string size using strlen(char *string) function from <string.h> char is 1 byte, the total number of alphabets would be the size of the string. Example program: #include <stdio.h> #include <string.h> int main() { char newString1[] = {'W','e','l','c','o','m','e','\0'}; char newString2[] = “Bye Bye"; //size of string Welcome printf ("Size of ‘%s’ is %d\n", newString1,strlen(newString1); //size of string Good Bye printf ("\nSize of ‘%s’ is %d\n",newString2,strlen(newString2)); return 0; }

Example 3.2: Calculation of String Size using Build-in Function Calculation of string size using strlen(char *string) function from <string.h> char is 1 byte, the total number of alphabets would be the size of the string. Example program: #include <stdio.h> #include <string.h> int main() { char newString1[] = {'W','e','l','c','o','m','e','\0'}; char newString2[] = “Bye Bye"; //size of string Welcome printf ("Size of ‘%s’ is %d\n", newString1,strlen(newString1); //size of string Good Bye printf ("\nSize of ‘%s’ is %d\n",newString2,strlen(newString2)); return 0; } Size of `Welcome’ is 7 Size of `Bye Bye’ is 8

Example 4.1: Copy String Another without Build-in Function Calculation of string size by measuring number of elements from the string Example program: #include <stdio.h> int main() { char newString1[50] = {'W','e','l','c','o','m','e','\0'}; char newString2[50] = “Bye Bye"; int i; printf(“Before String Copy\n"); printf(“newString1 is %s\n",newString1); printf(“newString2 is %s\n\n",newString2); for(i=0;newString1[i]!='\0';i++) newString2[i]=newString1[i]; printf(“After String Copy\n"); printf(“newString2 is %s\n",newString2); return 0; }

Example 4.1: Copy String Another without Build-in Function Calculation of string size by measuring number of elements from the string Example program: #include <stdio.h> int main() { char newString1[50] = {'W','e','l','c','o','m','e','\0'}; char newString2[50] = “Bye Bye"; int i; printf(“Before String Copy\n"); printf(“newString1 is %s\n",newString1); printf(“newString2 is %s\n\n",newString2); for(i=0;newString1[i]!='\0';i++) newString2[i]=newString1[i]; printf(“After String Copy\n"); printf(“newString2 is %s\n",newString2); return 0; } Before String Copy newString1 is Welcome newString2 is Bye Bye After String Copy newString2 is Welcome

Example 4.2: Copy String Another using Build-in Function Calculation of string size by measuring number of elements from the string Example program: #include <stdio.h> int main() { char newString1[50] = {'W','e','l','c','o','m','e','\0'}; char newString2[50] = “Bye Bye"; int i; printf(“Before String Copy\n"); printf(“newString1 is %s\n",newString1); printf(“newString2 is %s\n\n",newString2); strcpy(newString2,newString1); printf(“After String Copy\n"); printf(“newString2 is %s\n",newString2); return 0; }

Example 4.2: Copy String Another using Build-in Function Calculation of string size by measuring number of elements from the string Example program: #include <stdio.h> int main() { char newString1[50] = {'W','e','l','c','o','m','e','\0'}; char newString2[50] = “Bye Bye"; int i; printf(“Before String Copy\n"); printf(“newString1 is %s\n",newString1); printf(“newString2 is %s\n\n",newString2); strcpy(newString2,newString1); printf(“After String Copy\n"); printf(“newString2 is %s\n",newString2); return 0; } Before String Copy newString1 is Welcome newString2 is Bye Bye After String Copy newString2 is Welcome

Controlling Case of a Character In C, upper case letter, e.g. ‘K’ is not equal to lower case ‘k’ So in C programming, you usually use: if (cChoice == ‘K’ || cChoice == ‘k’), OR while (cChoice == ‘Y’ || cChoice == ‘y’) The case of a character can be controlled using tolower() and toupper() functions from <ctype.h> temporarily converts a letter/char to uppercase or lowercase before comparing it toupper(int c) tolower(int c) Also, can use functions that converts the whole string to upper or lowercase from <string.h> strupr(char *string) strlwr(char *string)

Example 5.1: Controlling Case of a Character … char cChoice; printf ( “Continue? (Y or N) : “); scanf (“%c”, &cChoice); while(tolower(choice)=='y') { scanf("%s",&choice); }

Example 5.2: Controlling Case of a Character //To convert a string to uppercase #include <stdio.h> #include <string.h> void main() { char acName[20]; //declare an array of //characters 0-79 printf("Enter in a name in lowercase\n"); scanf( "%s", acName ); strupr(acName); printf("The name in uppercase is %s", acName ); }

Example 5.2: Controlling Case of a Character //To convert a string to uppercase #include <stdio.h> #include <string.h> void main() { char acName[20]; //declare an array of //characters 0-79 printf("Enter in a name in lowercase\n"); scanf( "%s", acName ); strupr(acName); printf("The name in uppercase is %s", acName ); } Enter in a name in lowercase john The name in uppercase is JOHN

Controlling Case of a Character Real value does not changed. The functions only affect characters of letters or alphabets. does not affect numbers and special characters such as $ and % If the character is already lowercase or uppercase, the function will not affect the real value return the original value Example: char cRepeat = ‘Y’; cLetter = strupr(cRepeat); cLetter = ?

Strings Conversion Functions In <stdlib.h> (general utilities library) Convert strings of digits to integer and floating-point values

Strings Comparison Functions Comparing strings Computer compares numeric ASCII codes of characters in string int strcmp( const char *s1, const char *s2 ); Compares string s1 to s2 Returns a negative number if s1 < s2, zero if s1 == s2 or a positive number if s1 > s2 int strncmp(const char *s1,const char *s2, size_t n ); Compares up to n characters of string s1 to s2 Returns values as above

ASCII Table ‘A’  65, ‘a’  97 ASCII Character Set 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 nul soh stx etx eot enq ack bel bs ht If vt ff cr so si dle dc1 dc2 dc3 dc4 nak syn etb can em sub esc fs gs rs us sp ! “ # $ % & ` ( ) * + , - . / : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ’ a b 10 d e f g h i j k l 11 n o p q r s t v 12 x y z { | } ~ del ‘A’  65, ‘a’  97

Example 6.1 : String Comparison #include <stdio.h> #include <string.h> int main() { char acString1[20], acString2[20]; //declaration int iResult; printf( "Enter two strings: " ); scanf( "%s %s", acString1, acString2 ); iResult = strcmp( acString1, acString2);//comparing acString1 and acString2 if (iResult > 0 ) printf( "\"%s\" is greater than \"%s\"\n",acString1, acString2 ); else if ( iResult == 0 ) printf( "\"%s\" is equal to \"%s\"\n",acString1, acString2 ); else printf( "\"%s\" is less than \"%s\"\n",acString1, acString2 ); return 0; }

Example 6.1 : String Comparison #include <stdio.h> #include <string.h> int main() { char acString1[20], acString2[20]; //declaration int iResult; printf( "Enter two strings: " ); scanf( "%s %s", acString1, acString2 ); iResult = strcmp( acString1, acString2 );//comparing acString1 and acString2 if ( iResult > 0 ) printf( "\"%s\" is greater than \"%s\"\n",acString1, acString2 ); else if ( iResult == 0 ) printf( "\"%s\" is equal to \"%s\"\n",acString1, acString2 ); else printf( "\"%s\" is less than \"%s\"\n",acString1, acString2 ); return 0; } Enter two strings: computer programming "computer" is less than "programming" Enter two strings: programming computer "programming" is greater than "computer"

Example 6.2 : String Comparison #include <stdio.h> #include <string.h> int main() { char acString1[ 20 ], acString2[ 20 ]; int iResult, iCompareCount; printf( "Enter two strings: " ); scanf( "%s %s", acString1, acString2 ); printf( "How many characters should be compared: " ); scanf( "%d", &iCompareCount ); iResult = strncmp( acString1, acString2, iCompareCount ); if (iResult > 0 ) printf( "\"%s\" is greater than \"%s\" up to %d characters\n", acString1, acString2, iCompareCount ); else if ( iResult == 0 ) printf( "\"%s\" is equal to \"%s\" up to %d characters\n", else printf( "\"%s\" is less than \"%s\" up to %d characters\n", return 0; }

Example 6.2 : String Comparison #include <stdio.h> #include <string.h> int main() { char acString1[ 20 ], acString2[ 20 ]; int iResult, iCompareCount; printf( "Enter two strings: " ); scanf( "%s %s", acString1, acString2 ); printf( "How many characters should be compared: " ); scanf( "%d", &iCompareCount ); iResult = strncmp( acString1, acString2, iCompareCount ); if (iResult > 0 ) printf( "\"%s\" is greater than \"%s\" up to %d characters\n", acString1, acString2, iCompareCount ); else if ( iResult == 0 ) printf( "\"%s\" is equal to \"%s\" up to %d characters\n", else printf( "\"%s\" is less than \"%s\" up to %d characters\n", return 0; } Enter two strings: computer computer How many characters should be compared: 8 "computer" is equal to “computer" up to 8 characters Enter two strings: computer comp How many characters should be compared: 4 "computer" is greater than “comp" up to 4 characters Enter two strings: comp computer How many characters should be compared: 5 “comp" is less than "computer" up to 5 characters

Built in Functions for String Handling strcpy Copies one string to another strncpy Copies n characters of one string to another strlen Finds length of a string strcat Appends a string strncat Appends n characters of string strcmp Compares two strings strncmp Compares n characters of two strings strcmpi Compares two strings, non-case sensitive strlwr Converts a string to lowercase strupr Converts string to uppercase strchr Finds first occurrence of a given character strnset Sets n characters of string to a given character strrchr Finds last occurrence of given character in string strrev Reverses string strset Sets all characters of string to a given character strspn Finds first substring from given character set in string

End Arrays & Strings