This document discusses handling of character strings in C. It explains that a string is a sequence of characters stored in memory as ASCII codes appended with a null terminator. It describes common string operations in C like reading, displaying, concatenating, comparing and extracting substrings. It also discusses functions like strlen(), strcat(), strcmp(), strcpy() for performing various operations on strings.
The document discusses strings in C programming. It defines strings as sequences of characters stored as character arrays that are terminated with a null character. It covers string literals, declaring and initializing string variables, reading and writing strings, and common string manipulation functions like strlen(), strcpy(), strcmp(), and strcat(). These functions allow operations on strings like getting the length, copying strings, comparing strings, and concatenating strings.
This document discusses handling of character strings in C programming. It covers declaring and initializing string variables as character arrays, reading strings from the terminal using scanf() and gets(), writing strings to the screen using printf() and puts(), performing arithmetic operations and comparisons on characters, concatenating strings, and commonly used string handling functions like strcpy(), strcat(), and strcmp().
This document provides an overview of string handling functions in C programming. It discusses how to declare strings, compare strings, concatenate strings, copy strings, and manipulate strings using pre-defined functions from the string.h header file. Examples are given for common string functions like strlen(), strcmp(), strcpy(), strcat(), etc. to illustrate how each function works and what it returns.
This document discusses strings in C programming. It defines strings as arrays of characters that end with a null terminator (\0). It explains how to initialize and print strings. Common string functions like strlen(), strcpy(), strcat(), and strcmp() are described. The document contrasts strings and character pointers, noting strings cannot be reassigned while pointers can. Finally, it lists and briefly explains other standard string library functions.
This document discusses handling character strings in C. It covers:
1. How strings are stored in memory as ASCII codes appended with a null terminator.
2. Common string operations like reading, comparing, concatenating and copying strings.
3. How to initialize, declare, read and write strings.
4. Useful string handling functions like strlen(), strcpy(), strcat(), strcmp() etc to perform various operations on strings.
The document discusses strings in C and C++. It explains that strings are not a built-in data type in C/C++ and describes C-style strings as character arrays terminated by a null character. It also discusses C++ string classes like std::string. The document provides examples of using C-style strings and C++ strings. It describes common string functions in C++ for manipulating and comparing strings.
1) A string is a one-dimensional array of characters terminated by a null character. Strings are declared using char arrays or string literals.
2) There are two ways to declare and initialize strings in C: using a char array and specifying the size, or using a string literal which automatically inserts a null terminator.
3) Common string functions include strlen() to return the length, strcpy() to copy one string to another, strcat() to concatenate strings, and strcmp() to compare two strings.
The document discusses string processing in C programming. Some key points:
- Strings are arrays of characters that must be null-terminated
- Common functions for initializing, displaying, reading, comparing, and manipulating strings are introduced
- Functions like strcpy, strcmp, strlen, strcat, strchr, and strstr are described for copying, comparing, finding length and substrings of strings
The document discusses strings in C programming language. It provides details about:
- Strings are arrays of characters terminated by a null character '\0'.
- Common functions to declare, initialize, print and manipulate strings like strlen(), strcpy(), strcat(), strcmp() etc.
- Important points about receiving and processing multi-word strings using scanf(), gets() and puts().
- Implementation of some string handling functions like xstrlen(), xstrcpy() to demonstrate their working.
Bsc cs i pic u-4 function, storage class and array and stringsRai University
The document discusses arrays and functions in C programming. It defines arrays as groups of related data items that share a common name. One-dimensional and multi-dimensional arrays are described. Functions are defined as reusable blocks of code that can take input arguments and return values. The key elements of functions like return values, arguments, and function calls are explained. Common string handling and mathematical functions are also summarized.
This document provides an overview of standard C library functions for handling strings and characters. It discusses functions for string input/output, conversion, manipulation, comparison, searching, and memory operations. Examples are given to demonstrate the use of functions like strcpy(), strcmp(), strtok(), memmove(), and strerror(). The document is intended to introduce common string and memory handling techniques used in applications like word processors, layout software, and typesetting programs.
The document discusses string operations in C, defining strings as arrays of characters with a null terminator, and covering functions for declaring, initializing, inputting, manipulating, comparing, searching, and copying strings using standard library functions like strlen(), strcpy(), strcmp(), strchr(), and more. It provides examples of using these string functions to declare, compare, concatenate, and copy strings in C code.
function, storage class and array and stringsRai University
The document discusses one-dimensional arrays in C programming. It defines arrays, explains how to declare and initialize them, and provides examples of accessing array elements. It also discusses reading and printing arrays, and summarizes common string handling functions in C like strcat(), strcmp(), and strcpy().
Btech i pic u-4 function, storage class and array and stringsRai University
Arrays allow storing multiple values of the same type under a common name. One-dimensional arrays use a single subscript to access elements, while multi-dimensional arrays use multiple subscripts. Strings are arrays of characters terminated by a null character. Functions allow breaking programs into modular reusable units. Functions can take arguments, return values, or do both. Variables declared inside functions have automatic storage, while those outside have external storage. Arrays and strings can be passed to functions. Recursion occurs when a function calls itself.
Functions torage class and array and strings-aneebkmct
Arrays allow storing multiple values of the same type under a common name. One-dimensional arrays use a single subscript to access elements, while multi-dimensional arrays use multiple subscripts. Strings are arrays of characters terminated by a null character. Functions allow breaking programs into smaller, reusable parts. Functions can accept arguments, return values, or have no arguments and return nothing. Variables declared inside functions have automatic storage, while those outside have external storage.
Mcai pic u 4 function, storage class and array and stringsRai University
Arrays allow storing multiple values of the same type under a common name. One-dimensional arrays use a single subscript to access elements, while multi-dimensional arrays use multiple subscripts. Strings are arrays of characters that end with a null character. Functions allow breaking programs into smaller, reusable parts. Functions can take arguments, return values, or do both. Variables declared inside functions have automatic storage, while those outside have external storage. Arrays and strings can be passed to functions. Recursion occurs when a function calls itself.
Strings are arrays of characters that end with a null character. They can be declared using character arrays or pointers. Strings passed to functions are passed by reference as pointers. Common string functions include strlen to get length, strcmp to compare strings, strcpy to copy one string to another, and strcat to concatenate strings. Strtok breaks a string into tokens delimited by a specified character.
Diploma ii cfpc u-4 function, storage class and array and stringsRai University
The document discusses various aspects of arrays and functions in C programming language. It explains that arrays allow storing multiple elements of the same type using a single name. One-dimensional and multi-dimensional arrays are described along with initialization and accessing of array elements. Common string handling functions like strcat(), strcmp(), strcpy() are also summarized. The document also provides the general forms of defining and calling functions in C and different categories of functions based on arguments and return values.
This document provides information about strings in C++. It defines a string as a collection of characters within double quotes. Strings are stored as character arrays terminated by a null character. The document discusses declaring and initializing strings, inputting strings from the user, and functions for manipulating strings like strcat(), strcmp(), and memcpy(). It also covers arrays of strings and comparing, concatenating, copying and other operations on strings.
The document discusses strings in C programming. It explains that strings are arrays of characters terminated by a null character. Strings can be declared as character arrays or using string pointers. It then provides examples of declaring and initializing strings. The document also discusses various string functions in C like strlen(), strcpy(), strcat(), gets(), puts() and how to perform operations on strings like reversing them, finding length, concatenating, copying and manipulating strings.
This document discusses strings in C programming. It defines strings as arrays of characters ending with a null character. It covers declaring and initializing strings, the difference between character and integer values, string input/output functions like scanf and printf, and character handling library functions. It also provides examples of using strings, checking string length and converting strings to integers.
C Programming/Strings. A string in C is merely an array of characters. The length of a string is determined by a terminating null character: '-' . So, a string with the contents, say, "abc" has four characters: 'a' , 'b' , 'c' , and the terminating null character.
At the end of this lecture students should be able to;
Define the declaration C strings.
Compare fixed length and variable length string.
Apply strings for functions.
Define string handling functions.
Apply taught concepts for writing programs.
The document discusses strings in C and C++. It explains that strings are not a built-in data type in C/C++ and describes C-style strings as character arrays terminated by a null character. It also discusses C++ string classes like std::string. The document provides examples of using C-style strings and C++ strings. It describes common string functions in C++ for manipulating and comparing strings.
1) A string is a one-dimensional array of characters terminated by a null character. Strings are declared using char arrays or string literals.
2) There are two ways to declare and initialize strings in C: using a char array and specifying the size, or using a string literal which automatically inserts a null terminator.
3) Common string functions include strlen() to return the length, strcpy() to copy one string to another, strcat() to concatenate strings, and strcmp() to compare two strings.
The document discusses string processing in C programming. Some key points:
- Strings are arrays of characters that must be null-terminated
- Common functions for initializing, displaying, reading, comparing, and manipulating strings are introduced
- Functions like strcpy, strcmp, strlen, strcat, strchr, and strstr are described for copying, comparing, finding length and substrings of strings
The document discusses strings in C programming language. It provides details about:
- Strings are arrays of characters terminated by a null character '\0'.
- Common functions to declare, initialize, print and manipulate strings like strlen(), strcpy(), strcat(), strcmp() etc.
- Important points about receiving and processing multi-word strings using scanf(), gets() and puts().
- Implementation of some string handling functions like xstrlen(), xstrcpy() to demonstrate their working.
Bsc cs i pic u-4 function, storage class and array and stringsRai University
The document discusses arrays and functions in C programming. It defines arrays as groups of related data items that share a common name. One-dimensional and multi-dimensional arrays are described. Functions are defined as reusable blocks of code that can take input arguments and return values. The key elements of functions like return values, arguments, and function calls are explained. Common string handling and mathematical functions are also summarized.
This document provides an overview of standard C library functions for handling strings and characters. It discusses functions for string input/output, conversion, manipulation, comparison, searching, and memory operations. Examples are given to demonstrate the use of functions like strcpy(), strcmp(), strtok(), memmove(), and strerror(). The document is intended to introduce common string and memory handling techniques used in applications like word processors, layout software, and typesetting programs.
The document discusses string operations in C, defining strings as arrays of characters with a null terminator, and covering functions for declaring, initializing, inputting, manipulating, comparing, searching, and copying strings using standard library functions like strlen(), strcpy(), strcmp(), strchr(), and more. It provides examples of using these string functions to declare, compare, concatenate, and copy strings in C code.
function, storage class and array and stringsRai University
The document discusses one-dimensional arrays in C programming. It defines arrays, explains how to declare and initialize them, and provides examples of accessing array elements. It also discusses reading and printing arrays, and summarizes common string handling functions in C like strcat(), strcmp(), and strcpy().
Btech i pic u-4 function, storage class and array and stringsRai University
Arrays allow storing multiple values of the same type under a common name. One-dimensional arrays use a single subscript to access elements, while multi-dimensional arrays use multiple subscripts. Strings are arrays of characters terminated by a null character. Functions allow breaking programs into modular reusable units. Functions can take arguments, return values, or do both. Variables declared inside functions have automatic storage, while those outside have external storage. Arrays and strings can be passed to functions. Recursion occurs when a function calls itself.
Functions torage class and array and strings-aneebkmct
Arrays allow storing multiple values of the same type under a common name. One-dimensional arrays use a single subscript to access elements, while multi-dimensional arrays use multiple subscripts. Strings are arrays of characters terminated by a null character. Functions allow breaking programs into smaller, reusable parts. Functions can accept arguments, return values, or have no arguments and return nothing. Variables declared inside functions have automatic storage, while those outside have external storage.
Mcai pic u 4 function, storage class and array and stringsRai University
Arrays allow storing multiple values of the same type under a common name. One-dimensional arrays use a single subscript to access elements, while multi-dimensional arrays use multiple subscripts. Strings are arrays of characters that end with a null character. Functions allow breaking programs into smaller, reusable parts. Functions can take arguments, return values, or do both. Variables declared inside functions have automatic storage, while those outside have external storage. Arrays and strings can be passed to functions. Recursion occurs when a function calls itself.
Strings are arrays of characters that end with a null character. They can be declared using character arrays or pointers. Strings passed to functions are passed by reference as pointers. Common string functions include strlen to get length, strcmp to compare strings, strcpy to copy one string to another, and strcat to concatenate strings. Strtok breaks a string into tokens delimited by a specified character.
Diploma ii cfpc u-4 function, storage class and array and stringsRai University
The document discusses various aspects of arrays and functions in C programming language. It explains that arrays allow storing multiple elements of the same type using a single name. One-dimensional and multi-dimensional arrays are described along with initialization and accessing of array elements. Common string handling functions like strcat(), strcmp(), strcpy() are also summarized. The document also provides the general forms of defining and calling functions in C and different categories of functions based on arguments and return values.
This document provides information about strings in C++. It defines a string as a collection of characters within double quotes. Strings are stored as character arrays terminated by a null character. The document discusses declaring and initializing strings, inputting strings from the user, and functions for manipulating strings like strcat(), strcmp(), and memcpy(). It also covers arrays of strings and comparing, concatenating, copying and other operations on strings.
The document discusses strings in C programming. It explains that strings are arrays of characters terminated by a null character. Strings can be declared as character arrays or using string pointers. It then provides examples of declaring and initializing strings. The document also discusses various string functions in C like strlen(), strcpy(), strcat(), gets(), puts() and how to perform operations on strings like reversing them, finding length, concatenating, copying and manipulating strings.
This document discusses strings in C programming. It defines strings as arrays of characters ending with a null character. It covers declaring and initializing strings, the difference between character and integer values, string input/output functions like scanf and printf, and character handling library functions. It also provides examples of using strings, checking string length and converting strings to integers.
C Programming/Strings. A string in C is merely an array of characters. The length of a string is determined by a terminating null character: '-' . So, a string with the contents, say, "abc" has four characters: 'a' , 'b' , 'c' , and the terminating null character.
At the end of this lecture students should be able to;
Define the declaration C strings.
Compare fixed length and variable length string.
Apply strings for functions.
Define string handling functions.
Apply taught concepts for writing programs.
This document discusses problem solving techniques in artificial intelligence, including state-space search and control strategies. It provides examples of representing problems as state spaces with start and goal states, such as the 8-puzzle and missionaries and cannibals problem. Search algorithms like breadth-first search are introduced for systematically exploring state spaces to find solutions. Production systems are also presented as a way to structure problem solving using rules and state transitions.
This document discusses knowledge representation techniques in artificial intelligence, including semantic networks, frames, and extended semantic networks. It provides examples of representing knowledge about various concepts such as animals, birds, and humans using predicates, semantic networks, and frames. Inheritance and deduction techniques are also described for semantic networks and extended semantic networks.
The document provides an overview of the topics covered in the Introduction to Artificial Intelligence unit, including:
- A brief history of AI from its origins in ancient myths to modern applications of machine learning.
- Key concepts in AI like what intelligence is, different categories of intelligent systems, foundations of AI in fields like mathematics, neuroscience and linguistics.
- Popular AI techniques, components of AI programs, subareas of AI, applications, and strategies for developing an AI that can play and win the tic-tac-toe game.
This document provides an overview of propositional logic concepts. It discusses:
- Propositional logic deals with validity and satisfiability of logical formulas using truth tables or deduction systems.
- Natural deduction is a deductive system that mimics natural reasoning using inference rules. Propositional formulas can be derived or proven in this system.
- Axiomatic systems use only axioms and rules of inference to prove formulas, requiring creative use of the minimal structure.
The document gives examples of proving formulas using these logical systems.
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingCeline George
The Accounting module in Odoo 17 is a complete tool designed to manage all financial aspects of a business. Odoo offers a comprehensive set of tools for generating financial and tax reports, which are crucial for managing a company's finances and ensuring compliance with tax regulations.
A measles outbreak originating in West Texas has been linked to confirmed cases in New Mexico, with additional cases reported in Oklahoma and Kansas. The current case count is 795 from Texas, New Mexico, Oklahoma, and Kansas. 95 individuals have required hospitalization, and 3 deaths, 2 children in Texas and one adult in New Mexico. These fatalities mark the first measles-related deaths in the United States since 2015 and the first pediatric measles death since 2003.
The YSPH Virtual Medical Operations Center Briefs (VMOC) were created as a service-learning project by faculty and graduate students at the Yale School of Public Health in response to the 2010 Haiti Earthquake. Each year, the VMOC Briefs are produced by students enrolled in Environmental Health Science Course 581 - Public Health Emergencies: Disaster Planning and Response. These briefs compile diverse information sources – including status reports, maps, news articles, and web content– into a single, easily digestible document that can be widely shared and used interactively. Key features of this report include:
- Comprehensive Overview: Provides situation updates, maps, relevant news, and web resources.
- Accessibility: Designed for easy reading, wide distribution, and interactive use.
- Collaboration: The “unlocked" format enables other responders to share, copy, and adapt seamlessly. The students learn by doing, quickly discovering how and where to find critical information and presenting it in an easily understood manner.
INTRO TO STATISTICS
INTRO TO SPSS INTERFACE
CLEANING MULTIPLE CHOICE RESPONSE DATA WITH EXCEL
ANALYZING MULTIPLE CHOICE RESPONSE DATA
INTERPRETATION
Q & A SESSION
PRACTICAL HANDS-ON ACTIVITY
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessMark Soia
Boost your chances of passing the 2V0-11.25 exam with CertsExpert reliable exam dumps. Prepare effectively and ace the VMware certification on your first try
Quality dumps. Trusted results. — Visit CertsExpert Now: https://www.certsexpert.com/2V0-11.25-pdf-questions.html
A measles outbreak originating in West Texas has been linked to confirmed cases in New Mexico, with additional cases reported in Oklahoma and Kansas. The current case count is 817 from Texas, New Mexico, Oklahoma, and Kansas. 97 individuals have required hospitalization, and 3 deaths, 2 children in Texas and one adult in New Mexico. These fatalities mark the first measles-related deaths in the United States since 2015 and the first pediatric measles death since 2003.
The YSPH Virtual Medical Operations Center Briefs (VMOC) were created as a service-learning project by faculty and graduate students at the Yale School of Public Health in response to the 2010 Haiti Earthquake. Each year, the VMOC Briefs are produced by students enrolled in Environmental Health Science Course 581 - Public Health Emergencies: Disaster Planning and Response. These briefs compile diverse information sources – including status reports, maps, news articles, and web content– into a single, easily digestible document that can be widely shared and used interactively. Key features of this report include:
- Comprehensive Overview: Provides situation updates, maps, relevant news, and web resources.
- Accessibility: Designed for easy reading, wide distribution, and interactive use.
- Collaboration: The “unlocked" format enables other responders to share, copy, and adapt seamlessly. The students learn by doing, quickly discovering how and where to find critical information and presenting it in an easily understood manner.
CURRENT CASE COUNT: 817 (As of 05/3/2025)
• Texas: 688 (+20)(62% of these cases are in Gaines County).
• New Mexico: 67 (+1 )(92.4% of the cases are from Eddy County)
• Oklahoma: 16 (+1)
• Kansas: 46 (32% of the cases are from Gray County)
HOSPITALIZATIONS: 97 (+2)
• Texas: 89 (+2) - This is 13.02% of all TX cases.
• New Mexico: 7 - This is 10.6% of all NM cases.
• Kansas: 1 - This is 2.7% of all KS cases.
DEATHS: 3
• Texas: 2 – This is 0.31% of all cases
• New Mexico: 1 – This is 1.54% of all cases
US NATIONAL CASE COUNT: 967 (Confirmed and suspected):
INTERNATIONAL SPREAD (As of 4/2/2025)
• Mexico – 865 (+58)
‒Chihuahua, Mexico: 844 (+58) cases, 3 hospitalizations, 1 fatality
• Canada: 1531 (+270) (This reflects Ontario's Outbreak, which began 11/24)
‒Ontario, Canada – 1243 (+223) cases, 84 hospitalizations.
• Europe: 6,814
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...larencebapu132
This is short and accurate description of World war-1 (1914-18)
It can give you the perfect factual conceptual clarity on the great war
Regards Simanchala Sarab
Student of BABed(ITEP, Secondary stage)in History at Guru Nanak Dev University Amritsar Punjab 🙏🙏
How to manage Multiple Warehouses for multiple floors in odoo point of saleCeline George
The need for multiple warehouses and effective inventory management is crucial for companies aiming to optimize their operations, enhance customer satisfaction, and maintain a competitive edge.
Odoo Inventory Rules and Routes v17 - Odoo SlidesCeline George
Odoo's inventory management system is highly flexible and powerful, allowing businesses to efficiently manage their stock operations through the use of Rules and Routes.
The ever evoilving world of science /7th class science curiosity /samyans aca...Sandeep Swamy
The Ever-Evolving World of
Science
Welcome to Grade 7 Science4not just a textbook with facts, but an invitation to
question, experiment, and explore the beautiful world we live in. From tiny cells
inside a leaf to the movement of celestial bodies, from household materials to
underground water flows, this journey will challenge your thinking and expand
your knowledge.
Notice something special about this book? The page numbers follow the playful
flight of a butterfly and a soaring paper plane! Just as these objects take flight,
learning soars when curiosity leads the way. Simple observations, like paper
planes, have inspired scientific explorations throughout history.
The *nervous system of insects* is a complex network of nerve cells (neurons) and supporting cells that process and transmit information. Here's an overview:
Structure
1. *Brain*: The insect brain is a complex structure that processes sensory information, controls behavior, and integrates information.
2. *Ventral nerve cord*: A chain of ganglia (nerve clusters) that runs along the insect's body, controlling movement and sensory processing.
3. *Peripheral nervous system*: Nerves that connect the central nervous system to sensory organs and muscles.
Functions
1. *Sensory processing*: Insects can detect and respond to various stimuli, such as light, sound, touch, taste, and smell.
2. *Motor control*: The nervous system controls movement, including walking, flying, and feeding.
3. *Behavioral responThe *nervous system of insects* is a complex network of nerve cells (neurons) and supporting cells that process and transmit information. Here's an overview:
Structure
1. *Brain*: The insect brain is a complex structure that processes sensory information, controls behavior, and integrates information.
2. *Ventral nerve cord*: A chain of ganglia (nerve clusters) that runs along the insect's body, controlling movement and sensory processing.
3. *Peripheral nervous system*: Nerves that connect the central nervous system to sensory organs and muscles.
Functions
1. *Sensory processing*: Insects can detect and respond to various stimuli, such as light, sound, touch, taste, and smell.
2. *Motor control*: The nervous system controls movement, including walking, flying, and feeding.
3. *Behavioral responses*: Insects can exhibit complex behaviors, such as mating, foraging, and social interactions.
Characteristics
1. *Decentralized*: Insect nervous systems have some autonomy in different body parts.
2. *Specialized*: Different parts of the nervous system are specialized for specific functions.
3. *Efficient*: Insect nervous systems are highly efficient, allowing for rapid processing and response to stimuli.
The insect nervous system is a remarkable example of evolutionary adaptation, enabling insects to thrive in diverse environments.
The insect nervous system is a remarkable example of evolutionary adaptation, enabling insects to thrive
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsDrNidhiAgarwal
Unemployment is a major social problem, by which not only rural population have suffered but also urban population are suffered while they are literate having good qualification.The evil consequences like poverty, frustration, revolution
result in crimes and social disorganization. Therefore, it is
necessary that all efforts be made to have maximum.
employment facilities. The Government of India has already
announced that the question of payment of unemployment
allowance cannot be considered in India
This chapter provides an in-depth overview of the viscosity of macromolecules, an essential concept in biophysics and medical sciences, especially in understanding fluid behavior like blood flow in the human body.
Key concepts covered include:
✅ Definition and Types of Viscosity: Dynamic vs. Kinematic viscosity, cohesion, and adhesion.
⚙️ Methods of Measuring Viscosity:
Rotary Viscometer
Vibrational Viscometer
Falling Object Method
Capillary Viscometer
🌡️ Factors Affecting Viscosity: Temperature, composition, flow rate.
🩺 Clinical Relevance: Impact of blood viscosity in cardiovascular health.
🌊 Fluid Dynamics: Laminar vs. turbulent flow, Reynolds number.
🔬 Extension Techniques:
Chromatography (adsorption, partition, TLC, etc.)
Electrophoresis (protein/DNA separation)
Sedimentation and Centrifugation methods.
1. STRING MANIPULATIONS IN C
In C language, an array of characters is known as a string. char
st[80];
This statement declares a string array with 80 characters.
The control character „0‟ which represents a null character is placed automatically at the
end of any string used.
STRING HANDLING FUNCTIONS IN C:
There are four important string Handling functions in C language.
(i) strlen( ) function
(ii) strcpy( ) function
(iii) strcat( ) function
(iv) strcmp( ) function
(I) strlen( )Function:
strlen( ) function is used to find the length of a character string. Ex:
int n;
char st[20] = “Bangalore”; n
= strlen(st);
This will return the length of the string 9 which is assigned to an integer variable n.
Note that the null charcter „0‟ available at the end of a string is not counted.
(II) strcpy( )Function:
strcpy( ) function is used to copy from one string to another string. Ex :
2. L R
char city[15];
strcpy(city, “BANGALORE”) ;
This will assign the string “BANGALORE” to the character variable city.
* Note that character value like
city = “BANGALORE”; cannot be assigned in C language.
(III)strcat( )Function:
strcat( ) function is used to join character, Strings. When two character strings are
joined, it is referred as concatenation of strings.
Ex:
char city[20] = “BANGALORE”;
char pin[8] = “-560001”;
strcat
city
,
pin
;
This will join the two strings and store the result in city as “BANGALORE – 560001”.
Note that the resulting string is always stored in the left side string variable.
(iv) strcmp( ) Function:
strcm ( ) function is used to compare two character strings.
• It returns a 0 when two strings are identical. Otherwise it returns a numerical value
which is the different in ASCII values of the first mismatching character of the strings being
3. compared.
char city[20] = “Madras”; char
town[20] = “Mangalore”;
strcmp(city, town);
• This will return an integer value „- 10‟ which is the difference in the ASCII values of
the first mismatching letters „D‟ and „N‟
• Note that the integer value obtained as the difference may be assigned to an integer
variable as follows:
int n;
n = strcmp(city, town);
READING / WRITING STRINGS:
• We use scanf ( ) function to read strings which do not have any white spaces. Ex:
scanf(“ %s ”, city );
• When this statement is executed, the user has to enter the city name
(eg “NEWDELHI”) without any white space (i.e not like “NEW DELHI”).
• The white space in the string will terminate the reading and only “NEW” is assigned to
city.
• To read a string with white spaces gets( ) function or a loop can be used as.
(i) gets(city);
(ii) do … while loop i
= 0;
do
{
4. Ch = getchar( );
city[ i ] = ch; i++;
}
while(ch ! = „ n ‟) ;
i - - ; city[ i ] = „0‟;
• The copy or assign a single character to a string variable, the assignment can be written
as given below;
city[ i ] = „N‟;
• When a string contains more than one character, the assignment is written as strcpy
(city, “NEW DELHI”);
atoi( ) Function:
atoi( ) function is a C library function which is used to convert a string of digits
to the integer value.
char st[10] = “24175” ;
int n;
n = atoi(st);
This will assign the integer value 24175 to the integer variable n.
(1) Write a C program to count the occurrence of a particular character in the given string.
Solution:
Consider a string “MISSISSIPPI”. Count the appearance of a character, say „S‟.
Program:
* program to count a character in a string * / #
include<stdio.h>
5. # include<conio.h> #
include<string.h>
main( )
{
char st[20], ch;
int count, l,i;
clrscr( );
printf(“ n Enter the string:”);
gets(st);
printf(“ n which char to be counted ?”);
scanf(“ %c”, &ch);
/* loop to check the occurrence of the character * / l =
strlen(st);
count = 0;
for( i=0; i < l; i++)
if(st[ i ] = = ch)
count ++;
printf(“ n the character %c occurs %d times”, ch, count);
getch( ) ;
}
• When this program is executed, the user has to enter the string and the character to be
counted in the given string.
Output:
Enter the string : MISSISSIPPI
6. Which char to be counted? S
The character S occurs 4 times.
Alternative Method:
• This program can also be written to compare the first character of the string with the
last, second with the second last and so on up to the middle of the string as shown.
0 1 2 3 4 5 6 7 8
• If all the characters are identical, then the string is a palindrome string.
• Otherwise the loop will be terminated.
(2) Write a C program to compare two strings which are given as input through keyboard
and print the alphabetically greater string.
Solution
The alphabetically greater string is the one whose ASCII value of the first letter is
greater than that of the second string.
Consider the two character strings.
St1 = “ALPHA”
St2 = “BEETA”
St2 is greater than st1 because the ASCII value of „B‟ in “BETA” is greater than that
of „A‟ in „ALPHA‟.
• Note that when the first letters of the two strings are identical, the second letters of
the strings are compared.
E R
H Y
7. /* PROGRAM TO PRINT ALPHABETICALLY GREATER STRING * /
# include<stdio.h>
# include<conio.h>
#include<string.h>
main( )
{
char st1[20], st2[20];
clrscr( );
printf(“ n Enter string:”);
scanf( “ %s ”,st1);
printf(“ n Enter string 2:”);
scanf( “ %s ”, st2);
if(strcmp(st1,st2)> 0)
printf(“n %s is alphabetically greater string”, st1);
else
printf(“ n %s is alphabetically greater string”, st2);
getch( );
}
• When this program is executed, the user has to enter the two strings.
• Note that strcmp( ) function returns a positive value when string 1 is greater & a
negative value when string 2 is greater.
Output:
Enter string 1 : ACPHA
Enter string 2 : BETA
8. BETA is alphabetically greater string.
PROGRAM TO ARRANGE NAMES IN ALPHABETICAL ORDER.
# include<stdio.h>
# include<conio.h>
#
include<string.h>
main( )
{
char names[50][20], temp[20]; int
n,i,j;
clrscr( ):
printf(“ n How many names?”);
scanf(“%d”, &n);
printf(“ n Enter the %d names one by one n”,n);
for( i=0; i<n; i++)
scanf(“%s”, names[ i ]);
/* loop to arrange names in alphabetical order * /
for( i=0; i<n-1; i++)
for ( j =i+1; j<n; j++)
if(strcmp(names[ i ], names[ j ]) > 0)
{
strcpy( temp, names[ i ]); strcpy(names[ i ], names[ j ]);
strcpy(names[ j ],temp);
/* loop to print the alphabetical list of names * / printf (“ n names in alphabetical order”);
for( i=0; i<n; i++)
9. printf(“n %s”, names[ i ]);
getch( );
}
• When this program is executed, the user has to first enter the total no of names
(n) and then all the names in the list.
• The names are compared, rearranged and printed in alphabetical order.
Output:
How many names? 4
Enter the 4 names one by one
DEEPAK
SHERI
N
SONIK
A
ARUN
Names in Alphabetical order
ARUN
DEEPAK
SHERIN
SONIKA
(3) Write a C program to convert a line in the lower case text to upper case.
Solution
Consider ASCII values of lower and upper case letters A
– 65 B – 66..................................... Z –
90
10. a - 97 b – 98 ......................................z – 122
* Note that the difference between the lower and upper case letters (ie. – 32) is used
for conversion.
/* PROGRAM TO CONVERT LOWER CASE TEST TO UPPER CASE * /
# include<stdio.h>
# include<conio.h>
#
include<string.h>
main( )
{
char
st[80]; int
i; clrscr( );
printf(“ n Enter a sentence : n”);
gets(st);
/* loop to convert lower case alphabet to upper case * / for(
i=0; i<strlen(st); i++)
if(st[ i ] >= „a‟ && st[ i ] <= „z‟)st[ i ] = st[ i ] – 32;
printf(“ n the converted upper case strings n %s”, st);
getch( );
}
OUTPUT:
Enter a sentence:
Logical thinking is a must to learn programming
The converted upper case string is
11. Additional String Handling Functions:
Some „C‟ compilers will accept the following string handling functions which
are available in header files string.h and ctype.h
Functions:
(i) strupr( ): to convert all alphabets in a string to upper case letters. Ex:
strupr(“ delhi ”) “ DELHI”
(ii) strlwr( ): To convert all alphabets in a string to lower case letters. Ex:
strlwr(“ CITY ”) “city”
(iii) strrev( ): To reverse a string
Ex: strrev(“ SACHIN ”) “NIHCAS”
(iv) strncmp( ): To compare first n characters of two strings. Ex:
m = strncmp (“ DELHI ”, “ DIDAR ”, 2);
m = -4
(v) strcmpi( ): To compare two strings with case in sensitive (neglecting upper
/ lower case)
Ex:
m=strcmpi(“ DELHI ”, “ delhi ”); m = 0.
12. (vi) strncat( ): To join specific number of letters to another string. Ex.
char s1[10] = “New”; char
s2[10] = “Delhi -41”;
strncat(s1,s2,3);
s1 will be “NewDel”.
Operations with Characters:
C language also supports operations with characters and these functions are
available in the header file “ctype.h”.
* Note that the value „1‟ or positive integer will be returned when acondition is
true, and value „0‟ will be returned when condition is false.
• Some „ctype.h‟ functions are listed below.
Function:
(i) isupper( ) : To test if a character is a upper case letters. Ex:
isupper(“A‟) 1
isupper(“a‟) 0
isupper(“8‟) 0
(ii) islower( ) : To test if a charcter is a lower case letter.
Ex:
islower(“n‟) 1
(iii)isalpha( ) : To test if a character is an alphabet. Ex:
isalpha(“K‟) 1
isalpha(“+‟) 0
(iv) isalnum( ) : To test if a character is an alphabet or number. Ex:
13. isalnum(“8‟) 1
isalnum(“y‟) 1
isalnum(“-‟) 0
(v)isdigit( ) : To test if a character is a number. Ex:
isdigit(“6‟) 1
isdigit(“a‟) 0
(vi) isxdigit( ) : To test if a character is a Hexa decimal number (0-9, A-F and a-
f are Hexa decimal digits)
Ex:
isxdigit(“9‟) 1
isxdigit(“A‟) 1
isxdigit(“M‟) 0
(vii) tolower( ) : To convert an alphabet to lower case letter Ex:
tolower(“A‟) a
(viii)toupper( ) : To convert an alphabet to upper case letter Ex:
toupper(“a‟) A.
Functions:-
Designing:-
Functions are an essential ingredient of all programs, large and small, and serve as our primary
medium to express computational processes ina programming language. So far, we have
discussed the formal properties of functions and how they are applied. We now turn to the topic
of what makes a good function. Fundamentally, the qualities of good functions all reinforce the
idea that functions are abstractions.
Each function should have exactly one job. That job should be identifiable with a
short name and characterizable in a single line oftext. Functions that perform multiple
jobs in sequence should be divided into multiple functions.
Don't repeat yourself is a central tenet of software engineering. Theso-called DRY
principle states that multiple fragments of code should not describe redundant logic.
14. Instead, that logic should be implemented once, given a name, and applied multiple
times. If youfind yourself copying and pasting a block of code, you have probably
found an opportunity for functional abstraction.
15. Functions should be defined generally. Squaring is not in thePython Library
precisely because it is a special case of
the pow function, which raises numbers to arbitrary powers.
These guidelines improve the readability of code, reduce the number oferrors, and often
minimize the total amount of code written.
Decomposing a complex task into concise functions is a skill that takesexperience to master.
Fortunately, Python provides several features tosupport your efforts.
Structured programs:-
Structured programming is a programming paradigm aimed atimproving the clarity,
quality, and development time of a
computer program by making extensive use of the structured controlflow constructs of
selection (if/then/else) and repetition (while and for), block structures, and subroutines.
Function in C:-
A function is a block of statements that performs a specific task. Suppose you are building an
application in C language and in one of your program, you need to perform a same task more
than once. In suchcase you have two options –
a) Use the same set of statements every time you want to perform thetask
b) Create a function to perform that task, and just call it every time youneed to perform
that task.
Using option (b) is a good practice and a good programmer always usesfunctions while writing
codes in C.
Types of functions
1) Predefined standard library functions – such
as puts(), gets(), printf(), scanf() etc – These are the functions which already have a definition
in header files (.h files like stdio.h), so we justcall them whenever there is a need to use them.
• 2) User Defined functions – The functions that we create in aprogram are
known as user defined functions.
Inter-Function Communication:-
16. When a function gets executed in the program, the execution control is transferred from calling a
function to called function and executes function definition, and finally comes back to the calling
function. In this process, both calling and called functions have to communicate witheach
other to exchange information. The process of exchanging information between calling and called
functions is called inter-function communication.
In C, the inter function communication is classified as follows...
Downward Communication
Upward Communication
Bi-directional Communication
Standard library functions:-
The standard library functions are built-in functions in C programming.These functions are
defined in header files. For example,
The printf() is a standard library function to send formatted output to the
screen (display output on the screen). This function is defined inthe stdio.h header file.
Hence, to use the printf() function, we need to include the stdio.h headerfile using #include
<stdio.h>.
The sqrt() function calculates the square root of a number. The functionis defined in the math.h
header file.
Passing Array to Functions:-
Just like variables, array can also be passed to a function as an argument. In this guide, we will
learn how to pass the array to a functionusing call by value and call by reference methods.
To understand this guide, you should have the knowledge offollowing C
Programming topics:
C – Array
17. Function call by value in C Function
call by reference in C
Passing array to function using call by value method
As we already know in this type of function call, the actual parameter iscopied to the formal
parameters.
#include<stdio.h>
voiddisp(charch)
{
printf("%c ",ch);
}
int main()
{
chararr[]={'a','b','c','d','e','f','g','h','i','j'}; for(int x=0;
x<10; x++)
{
/* I’m passing each element one by one using subscript*/disp(arr[x]);
}
return0;
}
Output:
a b c d e f g h i j
Passing array to function using call by reference
When we pass the address of an array while calling a function then this is called function call by
reference. When we pass an address as an argument, the function declaration should have a
pointer as a parameterto receive the passed address.
#include<stdio.h>
voiddisp(int*num)
{
printf("%d ",*num);
19. return0;
}
Output:
1234567890
How to pass an entire array to a function as an argument?
In the above example, we have passed the address of each array element one by one using a for
loop in C. However you can also pass anentire array to a function like this:
Note: The array name itself is the address of first element of that array.For example if array
name is arr then you can say that arr is equivalentto the &arr[0].
#include<stdio.h>
voidmyfuncn(int*var1,int var2)
{
/* The pointer var1 is pointing to the first element of
* the array and the var2 is the size of the array. In the
* loop we are incrementing pointer so that it points to
* the next element of the array on each increment.
*
*/
for(int x=0; x<var2; x++)
{
printf("Value of var_arr[%d] is: %d n", x,*var1);
/*increment pointer for next element fetch*/var1++;
}
}
int main()
{ intvar_arr[]={11,22,33,44,55,66,77};
21. Value of var_arr[6]is:77
Passing pointer to function:-
In this example, we are passing a pointer to a function. When we pass apointer as an
argument instead of a variable then the address of the variable is passed instead of the value.
So any change made by the function using the pointer is permanently made at the address of
passedvariable. This technique is known as call by reference in C.
#include<stdio.h>
voidsalaryhike(int *var,
int b)
{
*var = *var+b;
}
int main()
{
int salary=0, bonus=0;
printf("Enter the employee current
salary:");scanf("%d", &salary);
printf("Enter bonus:");
scanf("%d", &bonus);
salaryhike(&salary, bonus);
printf("Final salary: %d",
salary);return0;
}
Output:
Enter the employee current
salary:10000Enter bonus:2000
Final salary: 12000