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.
A function is a group of statements that together perform a task. Every C program has at least one function, which is main(), and all the most trivial programs can define additional functions. You can divide up your code into separate functions.
View study notes of Function overloading .you can also visit Tutorialfocus.net to get complete description step wise of the concerned topic.Other topics and notes of C++ are also explained.
A function is a group of statements that together perform a task. Every C program has at least one function, which is main(), and all the most trivial programs can define additional functions. You can divide up your code into separate functions.
View study notes of Function overloading .you can also visit Tutorialfocus.net to get complete description step wise of the concerned topic.Other topics and notes of C++ are also explained.
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.
• List is a collection, which is ordered and changeable. Allows duplicate members.
• Tuple is a collection, which is ordered and unchangeable. Allows duplicate members.
• Set is a collection, which is unordered and unindexed. No duplicate members.
• Dictionary is a collection, which is unordered, changeable and indexed. No duplicate members.
: String, List, Tuple, Dictionary
• List is a collection, which is ordered and changeable. Allows duplicate members.
• Tuple is a collection, which is ordered and unchangeable. Allows duplicate members.
• Set is a collection, which is unordered and unindexed. No duplicate members.
• Dictionary is a collection, which is unordered, changeable and indexed. No duplicate members.
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
The French Revolution, which began in 1789, was a period of radical social and political upheaval in France. It marked the decline of absolute monarchies, the rise of secular and democratic republics, and the eventual rise of Napoleon Bonaparte. This revolutionary period is crucial in understanding the transition from feudalism to modernity in Europe.
For more information, visit-www.vavaclasses.com
The Art Pastor's Guide to Sabbath | Steve ThomasonSteve Thomason
What is the purpose of the Sabbath Law in the Torah. It is interesting to compare how the context of the law shifts from Exodus to Deuteronomy. Who gets to rest, and why?
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
Synthetic fiber production is a fascinating and complex field that blends chemistry, engineering, and environmental science. By understanding these aspects, students can gain a comprehensive view of synthetic fiber production, its impact on society and the environment, and the potential for future innovations. Synthetic fibers play a crucial role in modern society, impacting various aspects of daily life, industry, and the environment. ynthetic fibers are integral to modern life, offering a range of benefits from cost-effectiveness and versatility to innovative applications and performance characteristics. While they pose environmental challenges, ongoing research and development aim to create more sustainable and eco-friendly alternatives. Understanding the importance of synthetic fibers helps in appreciating their role in the economy, industry, and daily life, while also emphasizing the need for sustainable practices and innovation.
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
This presentation provides a briefing on how to upload submissions and documents in Google Classroom. It was prepared as part of an orientation for new Sainik School in-service teacher trainees. As a training officer, my goal is to ensure that you are comfortable and proficient with this essential tool for managing assignments and fostering student engagement.
How to Split Bills in the Odoo 17 POS ModuleCeline George
Bills have a main role in point of sale procedure. It will help to track sales, handling payments and giving receipts to customers. Bill splitting also has an important role in POS. For example, If some friends come together for dinner and if they want to divide the bill then it is possible by POS bill splitting. This slide will show how to split bills in odoo 17 POS.
This is a presentation by Dada Robert in a Your Skill Boost masterclass organised by the Excellence Foundation for South Sudan (EFSS) on Saturday, the 25th and Sunday, the 26th of May 2024.
He discussed the concept of quality improvement, emphasizing its applicability to various aspects of life, including personal, project, and program improvements. He defined quality as doing the right thing at the right time in the right way to achieve the best possible results and discussed the concept of the "gap" between what we know and what we do, and how this gap represents the areas we need to improve. He explained the scientific approach to quality improvement, which involves systematic performance analysis, testing and learning, and implementing change ideas. He also highlighted the importance of client focus and a team approach to quality improvement.
2. Strings
Strings are a fundamental concept, but they are not a built-in data type in C/C++.
String is collection of characters.
C-Strings
◦ C-style string: character array terminated by first null character.
◦ Wide string: wide character array terminated by first null character.
C++ - Strings
◦ Several Classes
◦ Standard Template Class:
◦ std::basic_string, std::string, std::wstring
No inter-operability between C and C++ style strings.
3. String example
C-string
◦ Array of chars that is null terminated (‘0’).
C++ - string
• Object whose string type is defined in the <string> file has a large repertoire of functions (e.g. length,
replace, etc.)
char cs[ ] = “Napoleon”; // C-string
string s = “Napoleon”; // C++ - string
cout << s << “ has “ << s.length() << “ characters.n”;
s.replace(5, 2,”ia”); //changes s to “Napolian
4. Strings
C-style strings consist of a contiguous sequence of characters
terminated by and including the first null character.
◦ A pointer to a string points to its initial character.
◦ The length of a string is the number of bytes preceding the null character
◦ The value of a string is the sequence of the values of the contained characters,
in order.
h e l l o 0
length
5. C++ Strings
◦ Formatted Input: Stream extraction operator
◦ cin >> stringObject;
◦ the extraction operator >> formats the data that it receives through its input stream; it skips over whitespace
◦ Unformatted Input: getline function for a string
◦ getline( cin, s)
◦ does not skip over whitespace
◦ delimited by newline
◦ reads an entire line of characters into s
string s = “ABCDEFG”;
getline(cin, s); //reads entire line of characters into s
char c = s[2]; //assigns ‘C’ to c
S[4] = ‘*’; //changes s to “ABCD*FG”
7. 7
Functions
Character Macro Description
isalpha Returns true (a nonzero number) if the argument is a letter of the
alphabet. Returns 0 if the argument is not a letter.
isalnum Returns true (a nonzero number) if the argument is a letter of the
alphabet or a digit. Otherwise it returns 0.
isdigit Returns true (a nonzero number) if the argument is a digit 0–9.
Otherwise it returns 0.
islower Returns true (a nonzero number) if the argument is a lowercase
letter. Otherwise, it returns 0.
isprint Returns true (a nonzero number) if the argument is a printable
character (including a space). Returns 0 otherwise.
ispunct Returns true (a nonzero number) if the argument is a printable
character other than a digit, letter, or space. Returns 0
otherwise.
isupper Returns true (a nonzero number) if the argument is an uppercase
letter. Otherwise, it returns 0.
isspace Returns true (a nonzero number) if the argument is a whitespace
character. Whitespace characters are any of the following:
8. Program Code(ACSII)
// This program demonstrates some of the character testing
// functions.
#include <iostream.h>
#include <ctype.h>
void main(void)
{
char input;
cout << "Enter any character: ";
cin.get(input);
cout << "The character you entered is: " << input << endl;
cout << "Its ASCII code is: " << int(input) << endl;
if (isalpha(input))
cout << "That's an alphabetic character.n";
if (isdigit(input))
cout << "That's a numeric digit.n";
if (islower(input))
cout << "The letter you entered is lowercase.n";
if (isupper(input))
cout << "The letter you entered is uppercase.n";
if (isspace(input))
cout << "That's a whitespace character.n";
}
Enter any character: A
The character you entered is: A
Its ASCII code is: 65
That's an alphabetic character.
The letter you entered is uppercase.
OUTPUT
Enter any character: 7 [Enter]
The character you entered is: 7
Its ASCII code is: 55
That's a numeric digit.
OUTPUT
9. 9
Character Case Conversion
The C++ library offers functions for converting a character to upper or lower case.
◦ Be sure to include ctype.h header file
Function Description
toupper Returns the uppercase equivalent of its argument.
tolower Returns the lowercase equivalent of its argument.
10. 10
Sample Code
// This program calculates the area of a circle. It asks the
// user if he or she wishes to continue. A loop that
// demonstrates the toupper function repeats until the user
// enters 'y', 'Y', 'n', or 'N'.
#include <iostream.h>
#include <ctype.h>
void main(void)
{
const float pi = 3.14159;
float radius;
char go;
cout << "This program calculates the area of a circle.n";
cout.precision(2);
cout.setf(ios::fixed);
do
{
cout << "Enter the circle's radius: ";
cin >> radius;
cout << "The area is " << (pi * radius * radius);
cout << endl;
do
{
cout << "Calculate another? (Y or N) ";
cin >> go;
} while (toupper(go) != 'Y' && toupper(go) != 'N');
} while (toupper(go) == 'Y');
}
Enter the circle's radius: 10
The area is 314.16
Calculate another? (Y or N) b
Calculate another? (Y or N) y
Enter the circle's radius: 1
The area is 3.14
Calculate another? (Y or N) n
OUTPUT
11. 11
String Function
Function Description
strlen Accepts a C-string or a pointer to a string as an argument. Returns the length of the
string (not including the null terminator. Example Usage: len = strlen(name);
strcat Accepts two C-strings or pointers to two strings as arguments. The function appends
the contents of the second string to the first string. (The first string is altered, the
second string is left unchanged.) Example Usage: strcat(string1, string2);
strcpy Accepts two C-strings or pointers to two strings as arguments. The function copies
the second string to the first string. The second string is left unchanged. Example
Usage: strcpy(string1, string2);
strncpy Accepts two C-strings or pointers to two strings and an integer argument. The third
argument, an integer, indicates how many characters to copy from the second string
to the first string. If the string2 has fewer than n characters, string1 is padded with
'0' characters. Example Usage: strncpy(string1, string2, n);
strcmp Accepts two C-strings or pointers to two string arguments. If string1 and string2are
the same, this function returns 0. If string2 is alphabetically greater than string1, it
returns a negative number. If string2 is alphabetically less than string1, it returns a
positive number. Example Usage: if (strcmp(string1, string2))
strstr Accepts two C-strings or pointers to two C-strings as arguments, searches for the
first occurrence of string2 in string1. If an occurrence of string2 is found, the
function returns a pointer to it. Otherwise, it returns a NULL pointer (address 0).
Example Usage: cout << strstr(string1, string2);