INDIAN INSTITUTE OF TECHNOLOGY KANPURESC 111M Lec13.pptxAbhimanyuChaure
This is an presentation of c programming language which is taught at indian institute of technology kanpur in first year first semester under bachelor of technology or bachelor of science.
Presentation more c_programmingcharacter_and_string_handling_KarthicaMarasamy
The document discusses C string operations like strcpy, strcat, strcmp, and strlen. It provides examples of using each function, including copying one string into another with strcpy, appending strings with strcat, comparing strings alphabetically with strcmp, and getting the length of a string with strlen. It also covers basic string declarations and built-in functions for manipulating characters.
This document discusses strings in C programming. It defines strings as arrays of characters terminated with a null character. It describes four methods of initializing strings: assigning a string literal with or without size, assigning characters individually with size, and assigning characters individually without size. It also covers string functions like strlen(), strcpy(), strcat(), and strcmp() to get the length, copy, concatenate, and compare strings. Finally, it discusses string arrays as two-dimensional character arrays where each string is terminated with a null character. An example program is provided to print an array of strings.
This document discusses strings in C programming. It defines strings as arrays of characters terminated by a null character. Strings must be declared as character arrays, specifying the array size. Common string functions like strcpy(), strcat(), strcmp(), and strlen() are described as well as how to initialize, copy, concatenate, compare and get the length of strings. The document provides examples of declaring, initializing and using strings in C code.
This document discusses strings in C programming. It defines strings as arrays of characters terminated by a null character. Strings must be declared as character arrays, specifying the array size. Common string functions like strcpy(), strcat(), strcmp(), and strlen() are described as well as how to initialize, copy, concatenate, compare and find the length of strings. The document provides examples of declaring, initializing and using strings in C code.
This document discusses strings in C programming. It defines strings as arrays of characters terminated by a null character. Strings must be declared as character arrays, specifying the array size. Common string functions like strcpy(), strcat(), strcmp(), and strlen() are described along with examples of how to use each function to copy, concatenate, compare, and find the length of strings. The document provides details on initializing strings, rules for declaring strings, and examples of string operations in C code.
The document discusses strings in C programming. It defines strings as finite sequences of characters that can be implemented as arrays of bytes or characters. It describes common string operations like searching, sorting, trimming, insertion, and deletion. It also lists various string manipulation functions in C like strcat, strcpy, strlen, and their applications in areas like text editing, search engines, and computational biology.
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.
Strings in C programming can be represented as arrays of characters terminated by a null character. A string is initialized by enclosing the characters within double quotes. Functions like strcpy(), strcat(), strcmp(), strlen() etc in string.h header file can perform operations on strings like copying, concatenating, comparing and finding length.
Strings in C programming can be represented as arrays of characters terminated by a null character. A string is initialized by enclosing the characters within double quotes. Functions like strcpy(), strcat(), strcmp(), strlen() etc in string.h header file can perform operations on strings like copying, concatenating, comparing and finding length.
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 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 C string functions. It defines a string as an array of characters terminated with a null character. It notes that the standard library contains many built-in string handling functions in the string.h header file to manipulate strings. Some functions discussed include strlen() to return the length of a string, strrev() to reverse a string, strdup() to duplicate a string, strlwr() to convert a string to lowercase, and strupr() to convert a string to uppercase. Code examples are provided to demonstrate the use of these functions.
This document discusses strings in C programming language. It defines a string as an array of characters terminated by a null character. It explains how to declare and initialize strings, read and write strings, determine string length, concatenate strings, copy strings, compare strings, convert between strings and integers, and various string processing functions like reversing, converting case, etc. It provides examples of implementing these string operations both through character-wise processing and using predefined string header functions.
This document discusses C strings and functions for manipulating strings. It explains that in C, a string is an array of characters terminated with a null character. It describes different ways to declare and initialize strings. Functions like strcpy(), strcat(), strlen() from the string.h library are used to copy, concatenate and find the length of strings. The document also demonstrates how to read strings from the user using scanf() and fgets(), and how to traverse strings using a loop until the null character is reached.
String handling functions in C allow programmers to manipulate string data more easily. Some key string handling functions include strlen() to return the length of a string, strcpy() to copy one string to another, strcmp() to compare two strings, strcat() to concatenate strings, and strrev() to reverse a string. These functions take string arguments and perform operations like copying, comparing, concatenating, and reversing to manipulate string data. Examples are provided to demonstrate how each function works.
The document discusses strings in C including how to declare, initialize, input, output, and manipulate strings using standard library functions as well as how to manage arrays of strings. It provides examples of declaring and initializing strings, using scanf and gets to input strings, common string manipulation functions like strlen and strcpy, and demonstrates how to work with arrays of strings such as storing and sorting a list of names.
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 introduction to strings in C programming, including defining strings as character arrays, initializing strings, inputting and outputting strings, and pointers and strings. It also covers common string library functions like strlen(), strcpy(), strcat(), strcmp(), and strrev(). Finally, it includes examples of basic string programs demonstrating the use of these functions.
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.
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 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.
This document discusses C strings and string functions. It defines a C string as a sequence of characters terminated with a null character. Strings are stored as character arrays. It provides examples of declaring, initializing, reading, and passing strings. It also describes common string functions like strcpy(), strcat(), strcmp(), strlen() for copying, concatenating, comparing, and getting the length of strings.
This document discusses strings in C programming. It defines strings as arrays of characters terminated by a null character. Strings must be declared as character arrays, specifying the array size. Common string functions like strcpy(), strcat(), strcmp(), and strlen() are described along with examples of how to use each function to copy, concatenate, compare, and find the length of strings. The document provides details on initializing strings, rules for declaring strings, and examples of string operations in C code.
The document discusses strings in C programming. It defines strings as finite sequences of characters that can be implemented as arrays of bytes or characters. It describes common string operations like searching, sorting, trimming, insertion, and deletion. It also lists various string manipulation functions in C like strcat, strcpy, strlen, and their applications in areas like text editing, search engines, and computational biology.
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.
Strings in C programming can be represented as arrays of characters terminated by a null character. A string is initialized by enclosing the characters within double quotes. Functions like strcpy(), strcat(), strcmp(), strlen() etc in string.h header file can perform operations on strings like copying, concatenating, comparing and finding length.
Strings in C programming can be represented as arrays of characters terminated by a null character. A string is initialized by enclosing the characters within double quotes. Functions like strcpy(), strcat(), strcmp(), strlen() etc in string.h header file can perform operations on strings like copying, concatenating, comparing and finding length.
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 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 C string functions. It defines a string as an array of characters terminated with a null character. It notes that the standard library contains many built-in string handling functions in the string.h header file to manipulate strings. Some functions discussed include strlen() to return the length of a string, strrev() to reverse a string, strdup() to duplicate a string, strlwr() to convert a string to lowercase, and strupr() to convert a string to uppercase. Code examples are provided to demonstrate the use of these functions.
This document discusses strings in C programming language. It defines a string as an array of characters terminated by a null character. It explains how to declare and initialize strings, read and write strings, determine string length, concatenate strings, copy strings, compare strings, convert between strings and integers, and various string processing functions like reversing, converting case, etc. It provides examples of implementing these string operations both through character-wise processing and using predefined string header functions.
This document discusses C strings and functions for manipulating strings. It explains that in C, a string is an array of characters terminated with a null character. It describes different ways to declare and initialize strings. Functions like strcpy(), strcat(), strlen() from the string.h library are used to copy, concatenate and find the length of strings. The document also demonstrates how to read strings from the user using scanf() and fgets(), and how to traverse strings using a loop until the null character is reached.
String handling functions in C allow programmers to manipulate string data more easily. Some key string handling functions include strlen() to return the length of a string, strcpy() to copy one string to another, strcmp() to compare two strings, strcat() to concatenate strings, and strrev() to reverse a string. These functions take string arguments and perform operations like copying, comparing, concatenating, and reversing to manipulate string data. Examples are provided to demonstrate how each function works.
The document discusses strings in C including how to declare, initialize, input, output, and manipulate strings using standard library functions as well as how to manage arrays of strings. It provides examples of declaring and initializing strings, using scanf and gets to input strings, common string manipulation functions like strlen and strcpy, and demonstrates how to work with arrays of strings such as storing and sorting a list of names.
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 introduction to strings in C programming, including defining strings as character arrays, initializing strings, inputting and outputting strings, and pointers and strings. It also covers common string library functions like strlen(), strcpy(), strcat(), strcmp(), and strrev(). Finally, it includes examples of basic string programs demonstrating the use of these functions.
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.
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 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.
This document discusses C strings and string functions. It defines a C string as a sequence of characters terminated with a null character. Strings are stored as character arrays. It provides examples of declaring, initializing, reading, and passing strings. It also describes common string functions like strcpy(), strcat(), strcmp(), strlen() for copying, concatenating, comparing, and getting the length of strings.
How to use nRF24L01 module with ArduinoCircuitDigest
Learn how to wirelessly transmit sensor data using nRF24L01 and Arduino Uno. A simple project demonstrating real-time communication with DHT11 and OLED display.
We introduce the Gaussian process (GP) modeling module developed within the UQLab software framework. The novel design of the GP-module aims at providing seamless integration of GP modeling into any uncertainty quantification workflow, as well as a standalone surrogate modeling tool. We first briefly present the key mathematical tools on the basis of GP modeling (a.k.a. Kriging), as well as the associated theoretical and computational framework. We then provide an extensive overview of the available features of the software and demonstrate its flexibility and user-friendliness. Finally, we showcase the usage and the performance of the software on several applications borrowed from different fields of engineering. These include a basic surrogate of a well-known analytical benchmark function; a hierarchical Kriging example applied to wind turbine aero-servo-elastic simulations and a more complex geotechnical example that requires a non-stationary, user-defined correlation function. The GP-module, like the rest of the scientific code that is shipped with UQLab, is open source (BSD license).
Value Stream Mapping Worskshops for Intelligent Continuous SecurityMarc Hornbeek
This presentation provides detailed guidance and tools for conducting Current State and Future State Value Stream Mapping workshops for Intelligent Continuous Security.
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITYijscai
With the increased use of Artificial Intelligence (AI) in malware analysis there is also an increased need to
understand the decisions models make when identifying malicious artifacts. Explainable AI (XAI) becomes
the answer to interpreting the decision-making process that AI malware analysis models use to determine
malicious benign samples to gain trust that in a production environment, the system is able to catch
malware. With any cyber innovation brings a new set of challenges and literature soon came out about XAI
as a new attack vector. Adversarial XAI (AdvXAI) is a relatively new concept but with AI applications in
many sectors, it is crucial to quickly respond to the attack surface that it creates. This paper seeks to
conceptualize a theoretical framework focused on addressing AdvXAI in malware analysis in an effort to
balance explainability with security. Following this framework, designing a machine with an AI malware
detection and analysis model will ensure that it can effectively analyze malware, explain how it came to its
decision, and be built securely to avoid adversarial attacks and manipulations. The framework focuses on
choosing malware datasets to train the model, choosing the AI model, choosing an XAI technique,
implementing AdvXAI defensive measures, and continually evaluating the model. This framework will
significantly contribute to automated malware detection and XAI efforts allowing for secure systems that
are resilient to adversarial attacks.
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfMohamedAbdelkader115
Glad to be one of only 14 members inside Kuwait to hold this credential.
Please check the members inside kuwait from this link:
https://www.rics.org/networking/find-a-member.html?firstname=&lastname=&town=&country=Kuwait&member_grade=(AssocRICS)&expert_witness=&accrediation=&page=1
Fluid mechanics is the branch of physics concerned with the mechanics of fluids (liquids, gases, and plasmas) and the forces on them. Originally applied to water (hydromechanics), it found applications in a wide range of disciplines, including mechanical, aerospace, civil, chemical, and biomedical engineering, as well as geophysics, oceanography, meteorology, astrophysics, and biology.
It can be divided into fluid statics, the study of various fluids at rest, and fluid dynamics.
Fluid statics, also known as hydrostatics, is the study of fluids at rest, specifically when there's no relative motion between fluid particles. It focuses on the conditions under which fluids are in stable equilibrium and doesn't involve fluid motion.
Fluid kinematics is the branch of fluid mechanics that focuses on describing and analyzing the motion of fluids, such as liquids and gases, without considering the forces that cause the motion. It deals with the geometrical and temporal aspects of fluid flow, including velocity and acceleration. Fluid dynamics, on the other hand, considers the forces acting on the fluid.
Fluid dynamics is the study of the effect of forces on fluid motion. It is a branch of continuum mechanics, a subject which models matter without using the information that it is made out of atoms; that is, it models matter from a macroscopic viewpoint rather than from microscopic.
Fluid mechanics, especially fluid dynamics, is an active field of research, typically mathematically complex. Many problems are partly or wholly unsolved and are best addressed by numerical methods, typically using computers. A modern discipline, called computational fluid dynamics (CFD), is devoted to this approach. Particle image velocimetry, an experimental method for visualizing and analyzing fluid flow, also takes advantage of the highly visual nature of fluid flow.
Fundamentally, every fluid mechanical system is assumed to obey the basic laws :
Conservation of mass
Conservation of energy
Conservation of momentum
The continuum assumption
For example, the assumption that mass is conserved means that for any fixed control volume (for example, a spherical volume)—enclosed by a control surface—the rate of change of the mass contained in that volume is equal to the rate at which mass is passing through the surface from outside to inside, minus the rate at which mass is passing from inside to outside. This can be expressed as an equation in integral form over the control volume.
The continuum assumption is an idealization of continuum mechanics under which fluids can be treated as continuous, even though, on a microscopic scale, they are composed of molecules. Under the continuum assumption, macroscopic (observed/measurable) properties such as density, pressure, temperature, and bulk velocity are taken to be well-defined at "infinitesimal" volume elements—small in comparison to the characteristic length scale of the system, but large in comparison to molecular length scale
The Fluke 925 is a vane anemometer, a handheld device designed to measure wind speed, air flow (volume), and temperature. It features a separate sensor and display unit, allowing greater flexibility and ease of use in tight or hard-to-reach spaces. The Fluke 925 is particularly suitable for HVAC (heating, ventilation, and air conditioning) maintenance in both residential and commercial buildings, offering a durable and cost-effective solution for routine airflow diagnostics.
its all about Artificial Intelligence(Ai) and Machine Learning and not on advanced level you can study before the exam or can check for some information on Ai for project
Passenger car unit (PCU) of a vehicle type depends on vehicular characteristics, stream characteristics, roadway characteristics, environmental factors, climate conditions and control conditions. Keeping in view various factors affecting PCU, a model was developed taking a volume to capacity ratio and percentage share of particular vehicle type as independent parameters. A microscopic traffic simulation model VISSIM has been used in present study for generating traffic flow data which some time very difficult to obtain from field survey. A comparison study was carried out with the purpose of verifying when the adaptive neuro-fuzzy inference system (ANFIS), artificial neural network (ANN) and multiple linear regression (MLR) models are appropriate for prediction of PCUs of different vehicle types. From the results observed that ANFIS model estimates were closer to the corresponding simulated PCU values compared to MLR and ANN models. It is concluded that the ANFIS model showed greater potential in predicting PCUs from v/c ratio and proportional share for all type of vehicles whereas MLR and ANN models did not perform well.
Sorting Order and Stability in Sorting.
Concept of Internal and External Sorting.
Bubble Sort,
Insertion Sort,
Selection Sort,
Quick Sort and
Merge Sort,
Radix Sort, and
Shell Sort,
External Sorting, Time complexity analysis of Sorting Algorithms.
2. • A string is a sequence of characters terminated by a null character ‘0’.
• ‘0’ is automatically encountered at the end of the string.
Declaration of string
char ch[6] ;
Here, ch is a string which can store a maximum of 5 characters and 1 character is reserved for
‘0’.
Introduction
8. Outputs:
G
G L
G L O
G L O B
G L O B A
G L O B A L
G
GL
GLO
GLOB
GLOBA
GLOBAL
9. Arithmetic Operations on Characters
To write a character in its integer representation, we may write it as an integer.
char x = ‘a’;
// 97
printf(“%dn”, x);
x = ‘z’–1;
printf(“%dn”, x); // 122-1 = 121
char number[21] = “1988”;
int year = atoi(number);
The function atoi() converts the string “1988” (contained in number) to its numeric equivalent 1988
and assigns it to the integer variable year.
String conversion functions are stored in the header file <std.lib.h>.
25. String Manipulation Functions
Function Action
#include<string.h>
strlen() finds the length of a string excluding ‘0’
strcpy() copies one string over another
strcmp() compares two strings
strcat() concatenates two strings
strlwr() Converts the string to lowercase letters
strupr() Converts the string to uppercase letters
27. String handling Functions
strlen()
strcpy()
strcmp()
strcat()
strlwr()
strupr()
works similar to string-assignment operator.
Syntax:
strcpy(string1, string2);
Assigns the contents of string2 to string1.
string2 may be a string variable or a string constant.
Example:
strcpy(city, “DELHI”);
will assign the string “DELHI” to the string variable city.
strcpy(city1, city2);
will assign the contents of the string variable city2 to the string variable city1.
The size of the array city1 should be large enough to receive the contents of
city2.
31. String handling Functions
char name1[21]="string", name2[21]="string";
int p1, p2, p3, p4;
p1=strcmp(name1, name2);
p2=strcmp(name1, "String");
p3=strcmp(name1, "Lohit");
p4=strcmp("RAM", "ROM");
0 1 2 3 4 5 6 -
-
-
-
20
s t r i n g 0
0 1 2 3 4 5 6 - - 20
- -
name1
name2
s t r i n g 0
0 1 2 3 4 5 6 - - 20
- -
S t r i n g 0
0 1 2 3 4 5
L o h i t 0
0 1 2 3
R A M 0
0 1 2 3
R O M 0
32. String handling Functions
strlen()
strcpy()
strcmp()
strcat()
strlwr()
strupr()
Joins two strings together.
Syntax:
strcat(string1, string2);
• string2 is appended to string1.
• It does so by removing the null character at the end of string1 and placing
string2 from there.
• The string at string2 remains unchanged.
• We must make sure that the size of string1 (to which string2 is appended) is
large enough to accommodate the final string.
37. Programs on strings
1. Write a C program, which reads your name
from the keyboard and outputs a list of
ASCII codes, which represent your name.
#include<stdio.h>
#include<string.h>
void main()
{
char name[21] ;
int i,len;
printf("Enter your name:n");
gets(name);
len=strlen(name);
printf("The name is ASCII form:n");
for(i=0;i<len;i++)
printf("%d",name[i]);
}
38. Programs on strings
2. Write a C program to find
length of a string without using
library function.
#include<stdio.h>
void main()
{
char a[21] ;
int len=0, i;
printf("Enter a stringn");
gets(a);
for(i=0;a[i]!='0';i++)
len++;
printf("The length of the string is: %d", len);
}
39. Programs on strings
3. Write a C program to input a string, convert lowercase letters to uppercase and vice
versa without using library functions.
#include <stdio.h> for(i=0;i<len;i++)
#include<string.h> {
void main() if(a[i]>='A' && a[i]<='Z')
{ a[i]=a[i]+32;
char a[21]; else if(a[i]>='a' && a[i]<='z')
int i, len; a[i]=a[i]-32;
printf("Enter a stringn"); }
gets(a); printf("The modified string is %s", a);
len=strlen(a); }
40. Programs on strings
4. Write a C program to find total number of alphabets, digits in a string without using library
functions.
#include <stdio.h> for(i=0;i<len;i++)
#include<string.h> {
void main() if((a[i]>='A' && a[i]<='Z') || (a[i]>='a' && a[i]<='z'))
{ alpha++;
char a[21]; else if(a[i]>='0' && a[i]<='9')
int i, len, alpha=0, digit=0; digit++;
printf("Enter a stringn"); }
gets(a); printf("No. of alphabets=%dnNo. of digits=%d", alpha, digit);
len=strlen(a); }
41. Programs on strings
5. Write a C program to count total number of vowels and consonants in a string.
#include<stdio.h>
#include<string.h>
void main()
{
char a[21];
int i, len, vow=0, cons=0;
printf("Enter a stringn");
gets(a);
strupr(a);
len=strlen(a);
for(i=0;i<len;i++)
{
if (isalpha(a[i]))
{
if(a[i]=='A' || a[i]=='E' || a[i]=='I' || a[i]== 'O' || a[i]=='U')
vow++;
else cons++;
}
}
printf("No. of vowels = %dn", vow);
printf("No. of consonants = %dn", cons);
}
42. Program to Sort String Characters in C
for (i = 0; i < n-1; i++)
{
for (j = i+1; j < n; j++)
{
if (string[i] > string[j])
{
temp = string[i];
string[i] = string[j];
string[j] = temp;
}
}
}
printf("String after sorting - %s n", string);
return 0;
}
#include <stdio.h>
#include <string.h>
int main (void)
{
char string[] = "simplyeasylearning";
char temp;
int i, j;
int n = strlen(string);
printf("String before sorting - %s n", string);
43. Program to Reverse String in C
#include <stdio.h>
int main() {
char s1[] = "TajMahal"; // String Given
char s2[8]; // Variable to store
reverse string
int length = 0;
int loop = 0;
while(s1[length] != '0’)
{
length++;
}
printf("nPrinting in reverse - ");
for(loop = --length; loop>=0; loop--)
printf("%c", s1[loop]);
loop = 0;
printf("nStoring in reverse - ");
while(length >= 0)
{
s2[length] = s1[loop];
length--;
loop++;
}
s1[loop] = '0'; // Terminates the string
printf("%sn", s2);
return 0;
}
44. Program to Swap Strings in C
#include <stdio.h>
int main()
{
char s1[] = "TajMahal";
char s2[] = "Dazzling";
char ch;
int index = 0;
//Character by Character
approach
printf("Before Swapping - n");
printf("Value of s1 - %s n", s1);
printf("Value of s2 - %s n", s2);
while(s1[index] != '0’)
{
ch = s1[index];
s1[index] = s2[index];
s2[index] = ch;
index++;
}
printf("After Swapping - n");
printf("Value of s1 - %s n", s1);
printf("Value of s2 - %s n", s2);
return 0;
}
45. String Copy Program in C
#include <stdio.h>
int main() {
char s1[] = "TajMahal"; // String
Given
char s2[8]; // Variable to hold
value
int length = 0;
while(s1[length] != '0’)
{
s2[length] = s1[length];
length++;
}
s2[length] = '0'; // Terminate the string
printf("Value in s1 = %s n", s1);
printf("Value in s2 = %s n", s2);
return 0;
}
46. Program to Compare Strings in C
#include <stdio.h>
int main()
{
char s1[] = "advise";
char s2[] = "advice";
int n = 0;
unsigned short flag = 1;
while (s1[n] != '0’)
{
if(s1[n] != s2[n])
{
flag = 0;
break;
}
n++;
if(flag == 1)
{
printf("%s and %s are identicaln", s1, s2);
}
else
{
printf("%s and %s are NOT identicaln", s1, s2);
}
return 0;
}
47. Program to Concatenate Strings in C
#include <stdio.h>
#include <string.h>
int main()
{
char s1[10] = "Taj";
char s2[] = "Mahal";
int i, j, n1, n2;
n1 = strlen(s1);
n2 = strlen(s2);
j = 0;
for(i = n1; i< n1+n2; i++ )
{
s1[i] = s2[j];
j++;
}
s1[i] = '0';
printf("%s", s1);
return 0;
}
48. Implementing a Palindrome String Program in C
#include <stdio.h>
#include <string.h>
int main()
{
char string[100], rev_string[100];
printf("Enter a string: ");
gets(string);
strcpy(rev_string, string);
strrev(rev_string);
if(strcmp(string, rev_string) == 0)
printf("%s is a palindrome string.n", string);
else
printf("%s is not a palindrome string.n", string);
return 0;
}
49. #include <stdio.h>
#include <string.h>
int main()
{
char str[] = { "abbba" };
// Start from first and
// last character of str
int l = 0;
int h = strlen(str) - 1;
WITHOUT USING LIBRARY FUNCTIONS
// Keep comparing characters while they are same
while (h > l)
{
if (str[l++] != str[h--])
{
printf("%s is not a palindromen", str);
return 0;
// will return from here
}
}
printf("%s is a palindromen", str);
return 0;
}
58. 2.6 String/Data Conversion
• A common set of applications, format data by either converting a sequence of
characters into corresponding data types or vice versa.
• Two such applications are parsing and telecommunications.
• C already has an extensive set of data conversion functions created for scanf and
printf.
59. String to Data conversion
• The string scan function is called sscanf ().
• This function scans a string as though the data were coming from a file.
• Just like fscanf (), it requires a format string to provide the formatting parameters for
the data.
• All fscanf () format codes are valid for the scan memory functions.
• Like fscanf (), the scan memory functions also return the number of variables
successfully formatted.
• If they attempt to "read" beyond the end of string-they return an end-of-file flag.
• The basic concept is shown in Figure 11-24.
61. String to Data conversion
sscanf() is a function used to read formatted input from a string.
It stands for "String Scan Formatted".
It is part of the C Standard Library and is declared in the <stdio.h> header file.
Syntax/The function prototype of sscanf() is:
int sscanf(const char *str, const char *format, ...);
Here,
• str is the string from which data is to be read.
• format is a format string that specifies how to interpret the data in the string str.
• The ellipsis ... indicates that sscanf() can accept a variable number of arguments. These arguments
are pointers to the variables where the extracted data will be stored.
NOTE:
Sscanf() is one-to-many function.
It splits one string into many variables.
62. Example for sscanf()
#include <stdio.h>
int main() {
char str[] = "John 25 123.45";
char name[20];
int age;
float salary;
sscanf(str, "%s %d %f", name, &age, &salary);
printf("Name: %sn", name);
printf("Age: %dn", age);
printf("Salary: %.2fn", salary);
return 0;
}
OUTPUT:
Name: John
Age: 25
Salary: 123.45
63. Data to String Conversion
• The string print function sprintf() follows the rules of fprintf().
• Rather the sending the data to a file, however, it simply "writes" them to a
string.
• When all data have been formatted to the string, a terminating null character
added to make the result a valid string.
• If an error is detected, sprintf() returns any negative value, traditionally EOF.
• If the formatting is successful, it returns the number of characters formatted,
not counting the terminating null character.
• The string print operation is shown in Figure 11-25.
65. • sprintf() is a function used to write formatted data to a string.
• It stands for "String Print Formatted".
• It is part of the C Standard Library and is declared in the <stdio.h> header file.
Syntax/The function prototype of sprintf() is:
int sprintf(char *str, const char *format, ...);
Here,
• str is the character array (string) where the formatted data will be stored.
• format is a format string that specifies how the data should be formatted.
• The ellipsis ... indicates that sprintf() can accept a variable number of
arguments. These arguments are the values to be formatted and inserted into the
string according to the format string.
66. Example for sprintf()
#include <stdio.h>
int main() {
char str[100];
int age = 25;
float salary = 123.45;
sprintf(str, "My age is %d and my salary is %.2f", age, salary);
printf("%sn", str);
return 0;
}
OUTPUT:
My age is 25 and my salary is
123.45
NOTE:
Sscanf() is many-to-one function.
It joins many pieces od data into one string.