Strings are arrays of characters that are null-terminated. They can be manipulated using functions like strlen(), strcpy(), strcat(), and strcmp(). The document discusses initializing and reading strings, passing strings to functions, and using string handling functions to perform operations like copying, concatenating, comparing, and reversing strings. It also introduces arrays of strings as 2D character arrays for storing multiple strings. Examples are provided to read and sort names stored as an array of strings.
Strings are arrays of characters that are null-terminated. They can be manipulated using functions like strlen(), strcpy(), strcat(), and strcmp(). The document discusses initializing and reading strings, passing strings to functions, and using string handling functions to perform operations like copying, concatenating, comparing, and reversing strings. It also describes arrays of strings, which are 2D character arrays used to store multiple strings. Examples are provided to demonstrate reading and sorting arrays of 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.
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 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 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.
Strings are arrays of characters that are null-terminated. They can be manipulated using functions like strlen(), strcpy(), strcat(), and strcmp(). The document discusses initializing and reading strings, passing strings to functions, and using string handling functions to perform operations like copying, concatenating, comparing, and reversing strings. It also introduces arrays of strings as 2D character arrays for storing multiple strings. Examples are provided to read and sort names stored as an array of strings.
Strings are arrays of characters that are null-terminated. They can be manipulated using functions like strlen(), strcpy(), strcat(), and strcmp(). The document discusses initializing and reading strings, passing strings to functions, and using string handling functions to perform operations like copying, concatenating, comparing, and reversing strings. It also describes arrays of strings, which are 2D character arrays used to store multiple strings. Examples are provided to demonstrate reading and sorting arrays of 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.
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 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 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 discusses strings in C++. It begins by explaining that strings are stored as character arrays terminated by a null character. It then covers declaring and initializing strings, accessing characters within strings, inputting and outputting strings using cin, gets(), and getline(), and comparing and copying strings. The document also discusses two-dimensional character arrays for storing arrays of strings. It provides examples of initializing, inputting, and displaying 2D string arrays.
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.
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 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.
This document discusses passing arrays to functions in C. It explains that to pass an array to a function, the array name is specified without brackets. The array size is usually also passed as a parameter to indicate the length of the array. Arrays are passed by reference, so any changes made to the array elements in the function affect the original array. It provides an example of a function prototype and definition that demonstrates passing and modifying an array.
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.
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.
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.
Array , Structure and Basic Algorithms covers key concepts like arrays, strings, structures, and algorithms. Arrays allow storing a collection of related data using a common name. Strings are arrays of characters that end with a null terminator. Structures group together different data types into one type for structured data. Algorithms specify the steps to solve problems and their complexity classifies efficiency.
A pointer is a variable that stores the address of another variable. Pointers allow a variable to indirectly access and modify the value of another variable. Pointers contain the address of the variable they point to. Common string operations like finding the length, comparing, copying and concatenating strings can be performed using standard library functions like strlen(), strcmp(), strcpy(), and strcat(). These functions make string handling easier compared to writing custom code.
C Programming Language is the most popular computer language and most used programming language till now. It is very simple and elegant language. This lecture series will give you basic concepts of structured programming language with C.
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.
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
A string in C is an array of characters that ends with a null character '\0'. Strings are stored in memory as arrays of characters with the null character added to the end. Common string operations in C include declaring and initializing strings, reading strings from users, and built-in string handling functions like strlen(), strcpy(), strcat(), and strcmp().
The document contains code for a C program that counts the lines, words, and characters in a given text. It prompts the user to enter text with a space between each word and press return when finished. It then counts the number of lines by checking for newline characters, words by checking for spaces, and characters by using strlen. It prints the number of lines, words, and characters in the input text.
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.
An array is a collection of similar data types stored in contiguous memory locations. Arrays in C can store primitive data types like int, char, float, etc. Elements of an array are accessed using indexes and they are stored sequentially in memory. Strings in C are arrays of characters terminated by a null character. Common functions to manipulate strings include strlen(), strcpy(), strcat(), strcmp(), strrev(), strlwr(), and strupr().
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++. It begins by explaining that strings are stored as character arrays terminated by a null character. It then covers declaring and initializing strings, accessing characters within strings, inputting and outputting strings using cin, gets(), and getline(), and comparing and copying strings. The document also discusses two-dimensional character arrays for storing arrays of strings. It provides examples of initializing, inputting, and displaying 2D string arrays.
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.
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 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.
This document discusses passing arrays to functions in C. It explains that to pass an array to a function, the array name is specified without brackets. The array size is usually also passed as a parameter to indicate the length of the array. Arrays are passed by reference, so any changes made to the array elements in the function affect the original array. It provides an example of a function prototype and definition that demonstrates passing and modifying an array.
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.
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.
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.
Array , Structure and Basic Algorithms covers key concepts like arrays, strings, structures, and algorithms. Arrays allow storing a collection of related data using a common name. Strings are arrays of characters that end with a null terminator. Structures group together different data types into one type for structured data. Algorithms specify the steps to solve problems and their complexity classifies efficiency.
A pointer is a variable that stores the address of another variable. Pointers allow a variable to indirectly access and modify the value of another variable. Pointers contain the address of the variable they point to. Common string operations like finding the length, comparing, copying and concatenating strings can be performed using standard library functions like strlen(), strcmp(), strcpy(), and strcat(). These functions make string handling easier compared to writing custom code.
C Programming Language is the most popular computer language and most used programming language till now. It is very simple and elegant language. This lecture series will give you basic concepts of structured programming language with C.
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.
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
A string in C is an array of characters that ends with a null character '\0'. Strings are stored in memory as arrays of characters with the null character added to the end. Common string operations in C include declaring and initializing strings, reading strings from users, and built-in string handling functions like strlen(), strcpy(), strcat(), and strcmp().
The document contains code for a C program that counts the lines, words, and characters in a given text. It prompts the user to enter text with a space between each word and press return when finished. It then counts the number of lines by checking for newline characters, words by checking for spaces, and characters by using strlen. It prints the number of lines, words, and characters in the input text.
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.
An array is a collection of similar data types stored in contiguous memory locations. Arrays in C can store primitive data types like int, char, float, etc. Elements of an array are accessed using indexes and they are stored sequentially in memory. Strings in C are arrays of characters terminated by a null character. Common functions to manipulate strings include strlen(), strcpy(), strcat(), strcmp(), strrev(), strlwr(), and strupr().
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.
Similar to Programming in C - Fundamental Study of Strings (20)
Null Bangalore | Pentesters Approach to AWS IAMDivyanshu
#Abstract:
- Learn more about the real-world methods for auditing AWS IAM (Identity and Access Management) as a pentester. So let us proceed with a brief discussion of IAM as well as some typical misconfigurations and their potential exploits in order to reinforce the understanding of IAM security best practices.
- Gain actionable insights into AWS IAM policies and roles, using hands on approach.
#Prerequisites:
- Basic understanding of AWS services and architecture
- Familiarity with cloud security concepts
- Experience using the AWS Management Console or AWS CLI.
- For hands on lab create account on [killercoda.com](https://killercoda.com/cloudsecurity-scenario/)
# Scenario Covered:
- Basics of IAM in AWS
- Implementing IAM Policies with Least Privilege to Manage S3 Bucket
- Objective: Create an S3 bucket with least privilege IAM policy and validate access.
- Steps:
- Create S3 bucket.
- Attach least privilege policy to IAM user.
- Validate access.
- Exploiting IAM PassRole Misconfiguration
-Allows a user to pass a specific IAM role to an AWS service (ec2), typically used for service access delegation. Then exploit PassRole Misconfiguration granting unauthorized access to sensitive resources.
- Objective: Demonstrate how a PassRole misconfiguration can grant unauthorized access.
- Steps:
- Allow user to pass IAM role to EC2.
- Exploit misconfiguration for unauthorized access.
- Access sensitive resources.
- Exploiting IAM AssumeRole Misconfiguration with Overly Permissive Role
- An overly permissive IAM role configuration can lead to privilege escalation by creating a role with administrative privileges and allow a user to assume this role.
- Objective: Show how overly permissive IAM roles can lead to privilege escalation.
- Steps:
- Create role with administrative privileges.
- Allow user to assume the role.
- Perform administrative actions.
- Differentiation between PassRole vs AssumeRole
Try at [killercoda.com](https://killercoda.com/cloudsecurity-scenario/)
Generative AI Use cases applications solutions and implementation.pdfmahaffeycheryld
Generative AI solutions encompass a range of capabilities from content creation to complex problem-solving across industries. Implementing generative AI involves identifying specific business needs, developing tailored AI models using techniques like GANs and VAEs, and integrating these models into existing workflows. Data quality and continuous model refinement are crucial for effective implementation. Businesses must also consider ethical implications and ensure transparency in AI decision-making. Generative AI's implementation aims to enhance efficiency, creativity, and innovation by leveraging autonomous generation and sophisticated learning algorithms to meet diverse business challenges.
https://www.leewayhertz.com/generative-ai-use-cases-and-applications/
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...DharmaBanothu
The Network on Chip (NoC) has emerged as an effective
solution for intercommunication infrastructure within System on
Chip (SoC) designs, overcoming the limitations of traditional
methods that face significant bottlenecks. However, the complexity
of NoC design presents numerous challenges related to
performance metrics such as scalability, latency, power
consumption, and signal integrity. This project addresses the
issues within the router's memory unit and proposes an enhanced
memory structure. To achieve efficient data transfer, FIFO buffers
are implemented in distributed RAM and virtual channels for
FPGA-based NoC. The project introduces advanced FIFO-based
memory units within the NoC router, assessing their performance
in a Bi-directional NoC (Bi-NoC) configuration. The primary
objective is to reduce the router's workload while enhancing the
FIFO internal structure. To further improve data transfer speed,
a Bi-NoC with a self-configurable intercommunication channel is
suggested. Simulation and synthesis results demonstrate
guaranteed throughput, predictable latency, and equitable
network access, showing significant improvement over previous
designs
Digital Twins Computer Networking Paper Presentation.pptxaryanpankaj78
A Digital Twin in computer networking is a virtual representation of a physical network, used to simulate, analyze, and optimize network performance and reliability. It leverages real-time data to enhance network management, predict issues, and improve decision-making processes.
Accident detection system project report.pdfKamal Acharya
The Rapid growth of technology and infrastructure has made our lives easier. The
advent of technology has also increased the traffic hazards and the road accidents take place
frequently which causes huge loss of life and property because of the poor emergency facilities.
Many lives could have been saved if emergency service could get accident information and
reach in time. Our project will provide an optimum solution to this draw back. A piezo electric
sensor can be used as a crash or rollover detector of the vehicle during and after a crash. With
signals from a piezo electric sensor, a severe accident can be recognized. According to this
project when a vehicle meets with an accident immediately piezo electric sensor will detect the
signal or if a car rolls over. Then with the help of GSM module and GPS module, the location
will be sent to the emergency contact. Then after conforming the location necessary action will
be taken. If the person meets with a small accident or if there is no serious threat to anyone’s
life, then the alert message can be terminated by the driver by a switch provided in order to
avoid wasting the valuable time of the medical rescue team.
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELijaia
As digital technology becomes more deeply embedded in power systems, protecting the communication
networks of Smart Grids (SG) has emerged as a critical concern. Distributed Network Protocol 3 (DNP3)
represents a multi-tiered application layer protocol extensively utilized in Supervisory Control and Data
Acquisition (SCADA)-based smart grids to facilitate real-time data gathering and control functionalities.
Robust Intrusion Detection Systems (IDS) are necessary for early threat detection and mitigation because
of the interconnection of these networks, which makes them vulnerable to a variety of cyberattacks. To
solve this issue, this paper develops a hybrid Deep Learning (DL) model specifically designed for intrusion
detection in smart grids. The proposed approach is a combination of the Convolutional Neural Network
(CNN) and the Long-Short-Term Memory algorithms (LSTM). We employed a recent intrusion detection
dataset (DNP3), which focuses on unauthorized commands and Denial of Service (DoS) cyberattacks, to
train and test our model. The results of our experiments show that our CNN-LSTM method is much better
at finding smart grid intrusions than other deep learning algorithms used for classification. In addition,
our proposed approach improves accuracy, precision, recall, and F1 score, achieving a high detection
accuracy rate of 99.50%.
Blood finder application project report (1).pdfKamal Acharya
Blood Finder is an emergency time app where a user can search for the blood banks as
well as the registered blood donors around Mumbai. This application also provide an
opportunity for the user of this application to become a registered donor for this user have
to enroll for the donor request from the application itself. If the admin wish to make user
a registered donor, with some of the formalities with the organization it can be done.
Specialization of this application is that the user will not have to register on sign-in for
searching the blood banks and blood donors it can be just done by installing the
application to the mobile.
The purpose of making this application is to save the user’s time for searching blood of
needed blood group during the time of the emergency.
This is an android application developed in Java and XML with the connectivity of
SQLite database. This application will provide most of basic functionality required for an
emergency time application. All the details of Blood banks and Blood donors are stored
in the database i.e. SQLite.
This application allowed the user to get all the information regarding blood banks and
blood donors such as Name, Number, Address, Blood Group, rather than searching it on
the different websites and wasting the precious time. This application is effective and
user friendly.
Road construction is not as easy as it seems to be, it includes various steps and it starts with its designing and
structure including the traffic volume consideration. Then base layer is done by bulldozers and levelers and after
base surface coating has to be done. For giving road a smooth surface with flexibility, Asphalt concrete is used.
Asphalt requires an aggregate sub base material layer, and then a base layer to be put into first place. Asphalt road
construction is formulated to support the heavy traffic load and climatic conditions. It is 100% recyclable and
saving non renewable natural resources.
With the advancement of technology, Asphalt technology gives assurance about the good drainage system and with
skid resistance it can be used where safety is necessary such as outsidethe schools.
The largest use of Asphalt is for making asphalt concrete for road surfaces. It is widely used in airports around the
world due to the sturdiness and ability to be repaired quickly, it is widely used for runways dedicated to aircraft
landing and taking off. Asphalt is normally stored and transported at 150’C or 300’F temperature
2. • Strings are array of characters i.e. they are
arranged one after another in
Thus, a character array is called
characters
memory.
string.
• Each character within the string is stored
within one element of the array successively.
• A string is always terminated by a null
character (i.e. slash zero 0).
Introduction
3. • Operations performed on
include:
– Reading and writing strings
– Copying one string to another
– Combining strings together
– Comparing strings for equality
– Extracting a portion of a string
character strings
Arrays and Strings…
4. • A string variable is declared as an array of
characters.
• Syntax:
char string_name[size];
• E.g. char name[20];
• When the compiler assigns a character string
to a character array, it automatically supplies a
null character (‘0’) at the end of the string
5. • Strings are initialized in either of the following two forms:
char name[4]={‘R’,‘A’,‘M’, ‘0’};
char name[]={‘R’,‘A’,‘M’, ‘0’};
char name[4]=“RAM”;
char name[]=“RAM”;
• When we initialize a character array by listing its
elements, the null terminator or the size of the array
must be provided explicitly.
Initializing String Variables
R A M 0
name[0] name[1] name[2] name[3]
10. String handling functions
• Strings need to be manipulated by
programmer.
• It can be done manually but is time
consuming.
11. #include <stdio.h>
#include <conio.h>
void main()
{
char input_string[50];
int i=0, length=0;
clrscr();
printf("nEnter your text:t");
gets(input_string);
while(input_string[i]!='0')
{
length++;
i++;
}
printf("nThe length of your text is: %d character(s)", length);
getch();
}
Counting length of the string
12. #include <stdio.h>
#include <conio.h>
void main()
{
char copy[50], paste[50];
int i;
clrscr();
printf("nEnter your name (to copy):t");
gets(copy);
for(i=0;copy[i]!='0';i++)
{
paste[i]=copy[i];
}
paste[i]='0';
printf("nThe name is (pasted as):t");
puts(paste);
getch();
}
Copying one string to another
13. • There are various string handling functions
define in string.h some of them are:
14. void main()
{
char input_string[50];
int length;
clrscr();
printf("nEnter your text:t");
gets(input_string);
length=strlen(input_string);
printf("nThe length of your text is: %d character(s)", length);
getch();
}
14
15. void main()
{
char copy[50], paste[50];
int i;
clrscr();
printf("nEnter your name (to copy):t");
gets(copy);
strcpy(paste, copy);
printf("nThe name is (pasted as):t");
puts(paste);
getch();
}
15
17. void main()
{
char str1[30],str2[40];
int diff;
clrscr();
printf("Enter first string:t");
gets(str1);
printf("nEnter second string:t");
gets(str2);
diff=strcmp(str1, str2);
if(diff>0)
printf("n%s is greater than %s by ASCII value difference %d", str1,
str2, diff);
else if(diff<0)
printf("n%s is smaller than %s byASCII value difference %d", str1,
str2, diff);
else
printf("n%s is same as %s", str1, str2);
getch();
}
17
19. • String is array of characters.
• Thus an array of string is 2-D array of
characters.
• E.g.
char names[5][10];
• Here, names[5][10] means 5 names having 10
characters each.
19
Arrays of Strings
20. Classwork
• WAPto read name of 5 persons using array of
strings and display them
• WAP to sort name of 5 persons in alphabetical
order
21. void main()
{
char names[5][10];
int i;
clrscr();
printf("nEnter name of 5 persons:");
for(i=0;i<5;i++)
scanf("%s", names[i]);
printf("nThe names are:");
for(i=0;i<5;i++)
printf("n%s", names[i]);
getch();
}
21
22. void main()
{
char names[5][10],temp[10];
int i, j;
clrscr();
printf("nEnter name of 5 persons:");
for(i=0;i<5;i++)
gets(names[i]);
for(i=0;i<5;i++)
{
for(j=i+1;j<5;j++)
{
if(strcmp(names[i], names[j])>0)
{
strcpy(temp, names[i]);
strcpy(names[i], names[j]);
strcpy(names[j], temp);
}
}
}
printf("nNames in ascending order:n");
for(i=0;i<5;i++)
puts(names[i]);
getch();
}
22