The document provides information about arrays, strings, and character handling functions in C language. It discusses:
1. Definitions and properties of arrays, including declaring, initializing, and accessing single and multi-dimensional arrays.
2. Built-in functions for testing and mapping characters from the ctype.h library, including isalnum(), isalpha(), iscntrl(), isdigit(), ispunct(), and isspace().
3. Strings in C being arrays of characters terminated by a null character. It discusses common string handling functions from string.h like strlen(), strrev(), strlwr(), strupr(), strcpy(), strcat(), and strcmp().
Programming Fundamentals Arrays and Strings imtiazalijoono
Programming Fundamentals
Arrays and Strings
• Arrays
• Initializing arrays
• Multidimensional arrays
• Arrays as arguments to functions
• Strings
• String functions
Accessing Individual Components
Declaring Arrays
Arrays: Example Garbage
Multidimensional Arrays
1) Write a C program using arrays that produces the multiplication of two 2x2 matrices.
3-Dimensional Array
Write a program of your own choice that makes use of arrays of more than 2 dimensions.
2-Dimensional Arrays
At the end of this lecture students should be able to;
Describe the C arrays.
Practice the declaration, initialization and access linear arrays.
Practice the declaration, initialization and access two dimensional arrays.
Apply taught concepts for writing programs.
Programming Fundamentals Arrays and Strings imtiazalijoono
Programming Fundamentals
Arrays and Strings
• Arrays
• Initializing arrays
• Multidimensional arrays
• Arrays as arguments to functions
• Strings
• String functions
Accessing Individual Components
Declaring Arrays
Arrays: Example Garbage
Multidimensional Arrays
1) Write a C program using arrays that produces the multiplication of two 2x2 matrices.
3-Dimensional Array
Write a program of your own choice that makes use of arrays of more than 2 dimensions.
2-Dimensional Arrays
At the end of this lecture students should be able to;
Describe the C arrays.
Practice the declaration, initialization and access linear arrays.
Practice the declaration, initialization and access two dimensional arrays.
Apply taught concepts for writing programs.
This is the last slide of advancedC - Advanced C part 3. In the previous slides we learnt all the fundamentals that is required to learnt Advanced C. In this last slide of Advanced C you will be learning about Multilevel pointers, Command line argument, different kinds of functions, and also you will gain deep knowledge on pre processor and user defined data types. This will help you to improve your knowledge in Advanced C
Introduction of arrays, Declaration of array, Initialization of array, Sorting, Multidimensional array. Some code examples that will make you clear about the concept of arrays.
https://github.com/ashim888/csit-c
1. Perform Linear Search and Binary Search on an array.
Descriptions of the programs:
Read and array of type integer.
Input element from user for searching.
Search the element by passing the array to a function and then returning the position of the element from the function else return -1 if the element is not found.
Display the positions where the element has been found.
2. Implement sparse matrix using array.
Description of program:
Read a 2D array from the user.
Store it in the sparse matrix form, use array of structures.
Print the final array.
3. Create a linked list with nodes having information about a student and perform.
Description of the program:
Insert a new node at specified position.
Delete of a node with the roll number of student specified.
Reversal of that linked list.
4. Create doubly linked list with nodes having information about an employee and perform Insertion at front of doubly linked list and perform deletion at end of that doubly linked list.
5. Create circular linked list having information about a college and perform Insertion at front perform Deletion at end.
6. Create a stack and perform Pop, Push, Traverse operations on the stack using Linear Linked list.
7. Create a Linear Queue using Linked List and implement different operations such as Insert, Delete, and Display the queue elements.
This is the last slide of advancedC - Advanced C part 3. In the previous slides we learnt all the fundamentals that is required to learnt Advanced C. In this last slide of Advanced C you will be learning about Multilevel pointers, Command line argument, different kinds of functions, and also you will gain deep knowledge on pre processor and user defined data types. This will help you to improve your knowledge in Advanced C
Introduction of arrays, Declaration of array, Initialization of array, Sorting, Multidimensional array. Some code examples that will make you clear about the concept of arrays.
https://github.com/ashim888/csit-c
1. Perform Linear Search and Binary Search on an array.
Descriptions of the programs:
Read and array of type integer.
Input element from user for searching.
Search the element by passing the array to a function and then returning the position of the element from the function else return -1 if the element is not found.
Display the positions where the element has been found.
2. Implement sparse matrix using array.
Description of program:
Read a 2D array from the user.
Store it in the sparse matrix form, use array of structures.
Print the final array.
3. Create a linked list with nodes having information about a student and perform.
Description of the program:
Insert a new node at specified position.
Delete of a node with the roll number of student specified.
Reversal of that linked list.
4. Create doubly linked list with nodes having information about an employee and perform Insertion at front of doubly linked list and perform deletion at end of that doubly linked list.
5. Create circular linked list having information about a college and perform Insertion at front perform Deletion at end.
6. Create a stack and perform Pop, Push, Traverse operations on the stack using Linear Linked list.
7. Create a Linear Queue using Linked List and implement different operations such as Insert, Delete, and Display the queue elements.
1sequences and sampling. Suppose we went to sample the x-axis from X.pdfrushabhshah600
1sequences and sampling. Suppose we went to sample the x-axis from Xmin to Xmax using a
step size of step
A)Draw a picture of what is going on.
B) Write a expression for n the total number of samples involved (in terms of Xmin, Xmax and
step)
C) Write out the sequence of x-samples
D) Write a direct and general expression for xi that captures the sequence
E) Write a recursive expression for the sequence
F) Write a program to compute and store the x-samples over the range -5x5 using a step size of
0.1 do everything in main ()
2 . We talked about the following string functions that are available in C (as long as you include
string.h):
int strlen(char str[])
void strcpy(char str1[], char str2[])
void strcat(char str1[], str2[])
Write your own versions of these functions; for example: int paul_strlen(int char str[]). Hint: for
your version of the strlen function, start at the first character in the array and keep counting until
you find the ‘\\0’ character (use a while loop for this). Note: Use your version of the strlen
function in the strcpy and strcat functions.
9. We want to insert a number into an array.
(a) Formulate the problem mathematically with two sequences: x and y. (b) Write a function of
the form:
insertNumIntoArray(int n, int array[], int num, int index)
The function inserts num into the array at the specified index. The rest of the array then follows.
For example, if num = 9 and index = 3 and array = [7 2 8 8 3 1 2] then the function will produce:
array = [7 2 8 9 8 3 1 2]
Note: assume that array is properly dimensioned to have at least 1 extra space for storage.
10. Repeat #2 by for the delete operation; that is, we want to delete a single element (at a
specified index) from an array; for example, suppose index = 3 and array = [50 70 10 90 60 20],
then the result will be
array: [50 70 10 60 20]
11. Repeat #2 by for an insert operation where we are inserting several values into the array. The
function should be of the form:
int insertArrayIntoArray(int n, int inArray[],
int nInsert, int insertArray[], int outArray[], int index)
The dimension of outArray is returned (explicitly). For example:
inArrayarray: [7 2 8 6 3 9]
insertArray: [50 60 70]
index: 2
outArray: [7 2 50 60 70 8 6 3 9]
Assume that outArray is large enough to hold all n + nInsert values.
Solution
#include
//Simulates strlen() library function
int paul_strlen(char str[])
{
int l;
for(l = 0; str[l] != \'\\0\'; l++) ;
return l;
}
//Simulates strcpy() library function
void paul_strcpy(char str1[], char str2[])
{
int c;
for(c = 0; str1[c] != \'\\0\'; c++)
str2[c] = str1[c];
str2[c] = \'\\0\';
printf(\"\ Original String: %s\", str1);
printf(\"\ Copied String: %s\", str2);
}
//Simulates strcat() library function
void paul_strcat(char str1[], char str2[])
{
int i, j;
for(i = 0; str1[i] != \'\\0\'; i++) ;
for (j = 0; str2[j] != \'\\0\'; i++, j++)
{
str1[i] = str2[j];
}
str1[i] = \'\\0\';
printf(\"\ Concatenated String: %s\", str1);
}
int main()
{
char data1[20], data2[20];
pri.
COURSE TITLE: SOFTWARE DEVELOPMENT VI
COURSE CODE: VIT 351
TOPICS COVERED:
FILES
FILES I/O STREAM
TYPES OF FILES
DRAWBACKS OF TRADITIONAL METHOD OF DATA STORAGE
CONCEPT OF BUFFER
MODES OF FILE OPENING
END OF FILE
PROCESSORS DIRECTIVES
MACROS
TYPES OF MACROS
DIFFERENCE BETWEEN MACROS AND FUNCTIONS
QUIZ SET 5
COURSE TITLE: SOFTWARE DEVELOPMENT VI
COURSE CODE: VIT 351
TOPICS COVERED:
USER DEFINED DATATYPES
STRUCTURE
UNION
TYPEDEF
DIFFERENCE BETWEEN STRUCTURE AND UNION
ENUMERATION (ENUM)
QUIZ SET 4
COURSE TITLE: SOFTWARE DEVELOPMENT VI
COURSE CODE: VIT 351
TOPICS COVERED:
INTRODUCTION TO POINTERS
TYPES OF POINTERS
POINTERS EXAMPLES
POINTERS ARITHMETICS
ADVANTAGES AND DISADVANTAGES OF POINTERS
STATIC MEMORY ALLOCATION
DYNAMIC MEMORY ALLOCATION
QUIZ SET 3
Course Title: Database Programming with SQL
Course Code: DEE 431
TOPICS COVER:
Database Terminologies
Drawbacks of Traditional System
Data processing Modes
Application of DBMS
Types of Database
Histroy of Database
Characteristics of Database
Advantages and Disadvantages of Database
Types of database architecture: 1 Tier, 2 Tier, 3 Tier
About
Indigenized remote control interface card suitable for MAFI system CCR equipment. Compatible for IDM8000 CCR. Backplane mounted serial and TCP/Ethernet communication module for CCR remote access. IDM 8000 CCR remote control on serial and TCP protocol.
• Remote control: Parallel or serial interface.
• Compatible with MAFI CCR system.
• Compatible with IDM8000 CCR.
• Compatible with Backplane mount serial communication.
• Compatible with commercial and Defence aviation CCR system.
• Remote control system for accessing CCR and allied system over serial or TCP.
• Indigenized local Support/presence in India.
• Easy in configuration using DIP switches.
Technical Specifications
Indigenized remote control interface card suitable for MAFI system CCR equipment. Compatible for IDM8000 CCR. Backplane mounted serial and TCP/Ethernet communication module for CCR remote access. IDM 8000 CCR remote control on serial and TCP protocol.
Key Features
Indigenized remote control interface card suitable for MAFI system CCR equipment. Compatible for IDM8000 CCR. Backplane mounted serial and TCP/Ethernet communication module for CCR remote access. IDM 8000 CCR remote control on serial and TCP protocol.
• Remote control: Parallel or serial interface
• Compatible with MAFI CCR system
• Copatiable with IDM8000 CCR
• Compatible with Backplane mount serial communication.
• Compatible with commercial and Defence aviation CCR system.
• Remote control system for accessing CCR and allied system over serial or TCP.
• Indigenized local Support/presence in India.
Application
• Remote control: Parallel or serial interface.
• Compatible with MAFI CCR system.
• Compatible with IDM8000 CCR.
• Compatible with Backplane mount serial communication.
• Compatible with commercial and Defence aviation CCR system.
• Remote control system for accessing CCR and allied system over serial or TCP.
• Indigenized local Support/presence in India.
• Easy in configuration using DIP switches.
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSEDuvanRamosGarzon1
AIRCRAFT GENERAL
The Single Aisle is the most advanced family aircraft in service today, with fly-by-wire flight controls.
The A318, A319, A320 and A321 are twin-engine subsonic medium range aircraft.
The family offers a choice of engines
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)MdTanvirMahtab2
This presentation is about the working procedure of Shahjalal Fertilizer Company Limited (SFCL). A Govt. owned Company of Bangladesh Chemical Industries Corporation under Ministry of Industries.
Vaccine management system project report documentation..pdfKamal Acharya
The Division of Vaccine and Immunization is facing increasing difficulty monitoring vaccines and other commodities distribution once they have been distributed from the national stores. With the introduction of new vaccines, more challenges have been anticipated with this additions posing serious threat to the already over strained vaccine supply chain system in Kenya.
Courier management system project report.pdfKamal Acharya
It is now-a-days very important for the people to send or receive articles like imported furniture, electronic items, gifts, business goods and the like. People depend vastly on different transport systems which mostly use the manual way of receiving and delivering the articles. There is no way to track the articles till they are received and there is no way to let the customer know what happened in transit, once he booked some articles. In such a situation, we need a system which completely computerizes the cargo activities including time to time tracking of the articles sent. This need is fulfilled by Courier Management System software which is online software for the cargo management people that enables them to receive the goods from a source and send them to a required destination and track their status from time to time.
Forklift Classes Overview by Intella PartsIntella Parts
Discover the different forklift classes and their specific applications. Learn how to choose the right forklift for your needs to ensure safety, efficiency, and compliance in your operations.
For more technical information, visit our website https://intellaparts.com
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxR&R Consult
CFD analysis is incredibly effective at solving mysteries and improving the performance of complex systems!
Here's a great example: At a large natural gas-fired power plant, where they use waste heat to generate steam and energy, they were puzzled that their boiler wasn't producing as much steam as expected.
R&R and Tetra Engineering Group Inc. were asked to solve the issue with reduced steam production.
An inspection had shown that a significant amount of hot flue gas was bypassing the boiler tubes, where the heat was supposed to be transferred.
R&R Consult conducted a CFD analysis, which revealed that 6.3% of the flue gas was bypassing the boiler tubes without transferring heat. The analysis also showed that the flue gas was instead being directed along the sides of the boiler and between the modules that were supposed to capture the heat. This was the cause of the reduced performance.
Based on our results, Tetra Engineering installed covering plates to reduce the bypass flow. This improved the boiler's performance and increased electricity production.
It is always satisfying when we can help solve complex challenges like this. Do your systems also need a check-up or optimization? Give us a call!
Work done in cooperation with James Malloy and David Moelling from Tetra Engineering.
More examples of our work https://www.r-r-consult.dk/en/cases-en/
Automobile Management System Project Report.pdfKamal Acharya
The proposed project is developed to manage the automobile in the automobile dealer company. The main module in this project is login, automobile management, customer management, sales, complaints and reports. The first module is the login. The automobile showroom owner should login to the project for usage. The username and password are verified and if it is correct, next form opens. If the username and password are not correct, it shows the error message.
When a customer search for a automobile, if the automobile is available, they will be taken to a page that shows the details of the automobile including automobile name, automobile ID, quantity, price etc. “Automobile Management System” is useful for maintaining automobiles, customers effectively and hence helps for establishing good relation between customer and automobile organization. It contains various customized modules for effectively maintaining automobiles and stock information accurately and safely.
When the automobile is sold to the customer, stock will be reduced automatically. When a new purchase is made, stock will be increased automatically. While selecting automobiles for sale, the proposed software will automatically check for total number of available stock of that particular item, if the total stock of that particular item is less than 5, software will notify the user to purchase the particular item.
Also when the user tries to sale items which are not in stock, the system will prompt the user that the stock is not enough. Customers of this system can search for a automobile; can purchase a automobile easily by selecting fast. On the other hand the stock of automobiles can be maintained perfectly by the automobile shop manager overcoming the drawbacks of existing system.
Immunizing Image Classifiers Against Localized Adversary Attacksgerogepatton
This paper addresses the vulnerability of deep learning models, particularly convolutional neural networks
(CNN)s, to adversarial attacks and presents a proactive training technique designed to counter them. We
introduce a novel volumization algorithm, which transforms 2D images into 3D volumetric representations.
When combined with 3D convolution and deep curriculum learning optimization (CLO), itsignificantly improves
the immunity of models against localized universal attacks by up to 40%. We evaluate our proposed approach
using contemporary CNN architectures and the modified Canadian Institute for Advanced Research (CIFAR-10
and CIFAR-100) and ImageNet Large Scale Visual Recognition Challenge (ILSVRC12) datasets, showcasing
accuracy improvements over previous techniques. The results indicate that the combination of the volumetric
input and curriculum learning holds significant promise for mitigating adversarial attacks without necessitating
adversary training.
Water scarcity is the lack of fresh water resources to meet the standard water demand. There are two type of water scarcity. One is physical. The other is economic water scarcity.
1. D.E.I. TECHNICAL COLLEGE
COURSE TITLE: Software Development-VI
SLIDE-2
COURSE CODE: VIT351
CLASS: DIPLOMA IN INFORMATION TECHNOLOGY VOCATIONAL (1ST YEAR)
SESSION: 2019-20
2. TOPICS COVERED
ARRAYS IN C
MULTIDIMENSIONAL ARRAYS
CHARACTER HANDLING IN C
STRING HANDLING IN C
QUIZ SET 2
3.
4. What is an Array?
Arrays are the collection of a finite number of homogeneous
data elements.
Elements of the array are referenced respectively by an
index set consisting of n consecutive numbers and are
stored respectively in successive memory locations.
The number n of elements is called the length or size of the
array.
GO TO TOPICS
5. Continue….
Array is a collection of similar elements. These similar elements
could be all ints, floats, doubles, chars, etc. Array is also known as
subscript variable.
Array can store a fixed-size sequential collection of elements of
the same type.
Array elements are stored in contiguous memory block.
Instead of declaring individual variables, such as number0,
number1, ..., and number99, you can declare one array variable.
Creating array is creating a group of variables and all its elements
are accessed via single name and different subscript values.
6. Properties of an Array
1) Indexing of an array begins from zero (0).
2) The variable name of array contains the base address of
the memory block.
3) The array variable are created at the time of
compilation.
4) The size of the array cannot be altered at runtime.
7. How to declare an Array?
Syntax:
dataType arrayName[arraySize];
For example,
float mark[5];
This is called single dimensional array.
Here, we declared an array, mark, of floating-point type.
And its size is 5. Meaning, it can hold 5 floating-point values.
It's important to note that the size and type of an array cannot
be changed once it is declared.
8. Array declaration by specifying size
// Array declaration by specifying size
int arr1[10];
// With recent C/C++ versions, we can also
// declare an array of user specified size
int n = 10;
int arr2[n];
Array declaration by initializing elements
// Array declaration by initializing elements
int arr[] = { 10, 20, 30, 40 }
// Compiler creates an array of size 4.
// above is same as "int arr[4] = {10, 20, 30, 40}"
Array declaration by specifying size and
initializing elements
// Array declaration by specifying size and
initializing elements
int arr[6] = { 10, 20, 30, 40 }
// Compiler creates an array of size 6,
initializes first
// 4 elements as specified by user and rest
two elements as 0.
// above is same as "int arr[] = {10, 20, 30, 40,
0, 0}"
9. How to access an Array?
Array elements are accessed by using an integer index.
Index of an array starts from 0 to size-1 i.e first element of arr array will be stored at arr[0]
address.
Example:
#include <stdio.h>
int main()
{
int arr[5];
arr[0] = 5;
arr[2] = -10;
arr[3 / 2] = 2; // this is same as arr[1] = 2
arr[3] = arr[0];
printf("%d %d %d %d", arr[0], arr[1], arr[2], arr[3]);
return 0;
}
10. Initialization of an Array
After an array is declared it must be initialized. Otherwise, it will
contain garbage value(any random value). An array can be initialized at either compile
time or at runtime.
data-type array-name[size] = { list of values };
/* Here are a few examples */
int marks[4]={ 67, 87, 56, 77 }; // integer array initialization
float area[5]={ 23.4, 6.8, 5.5 }; // float array initialization
int marks[4]={ 67, 87, 56, 77, 59 }; // Compile time error
In such case, there is no requirement to define the size. So it may also be written as the
following code.
int marks[]={20,30,40,50,60};
11. Example:
#include <stdio.h>
int main()
{
int marks[10], i, n, sum = 0, avg;
printf("Enter number of elements: ");
scanf("%d", &n);
for(i=0; i<n; i++)
{
printf("Enter number");
scanf("%d", &marks[i]);
// adding integers entered by the user to the sum variable
sum =sum+marks[i];
}
avg = sum/n;
printf("Average = %d", avg);
return 0;
}
12. Multi-dimensional Array
C language supports multidimensional arrays also.
The simplest form of a multidimensional array is the two-dimensional array.
Both the row's and column's index begins from 0.
Declaration:
data-type array-name[row-size][column-size]
/* Example */
int a[3][4];
GO TO TOPICS
13. Initialization of 2-D Array
int b[2] [3] = {12,65,78,45,33,21}; //valid
int b[ ] [3] = {12,65,78,45,33,21}; // valid
int b[2] [ ] = {12,65,78,45,33,21}; //invalid
int b[ ] [ ] = {12,65,78,45,33,21}; // invalid
14. Example: Adding two matrices
#include <stdio.h>
int main()
{ int i,j;
int a[2][2], b[2][2], result[2][2];
// Taking input using nested for loop
printf("Enter elements of 1st matrixn");
for (i = 0; i < 2; i++)
for (j = 0; j < 2; j++){
printf("Enter a%d%d: ", i + 1, j + 1);
scanf("%d", &a[i][j]); }
// Taking input using nested for loop
printf("Enter elements of 2nd matrixn");
for (i = 0; i < 2; i++)
for (j = 0; j < 2; j++){
printf("Enter b%d%d: ", i + 1, j + 1);
scanf("%d", &b[i][j]);
}
// adding corresponding elements of two arrays
for (i = 0; i < 2; i++)
for (j = 0; j < 2; j++)
{
result[i][j] = a[i][j] + b[i][j];
}
// Displaying the sum
printf("nSum Of Matrix:n");
for (i = 0; i < 2; i++)
for (j = 0; j < 2; j++)
{
printf("%dt", result[i][j]);
if (j == 1)
printf("n");
}
return 0;
}
15. Important Note:
The array elements can be accessed in a constant time by using the index of the
particular element.
To access an array element, address of an element is computed as an offset
from the base address of the array and one multiplication is needed to compute
what is supposed to be added to the base address to get the memory address
of the element
First the size of an element of that data type is calculated and then it is multiplied
with the index of the element to get the value to be added to the base address.
This process takes one multiplication and one addition. Since these two
operations take constant time, we can say the array access can be performed
in constant time.
16.
17. Dealing with Characters
ctype.h file includes functions that are useful for testing and
mapping characters.
All the functions defined in ctype.h accept int as a
parameter, whose value must be EOF or representable as
an unsigned char.
These functions return non-zero (true) if the argument
satisfies the condition described else the functions return
zero (false).
GO TO TOPICS
18. isalnum() Function
Description
The C library function void isalnum(int c) checks if the passed
character is alphanumeric.
Declaration
int isalnum(int c);
Parameters
c − This is the character to be checked.
Return Value
This function returns non-zero value if c is a digit or a letter, else it
returns 0.
19. Example:1#include <ctype.h>
#include<stdio.h>
int main () {
int var1 = 'a';
int var2 = '4';
int var3 = 't';
if( isalnum(var1) ) {
printf("var1 = |%c| is alphanumericn", var1 );
} else {
printf("var1 = |%c| is not alphanumericn", var1 ); }
if( isalnum(var2) ) {
printf("var2 = |%c| is alphanumericn", var2 );
} else {
printf("var2 = |%c| is not alphanumericn", var2 ); }
if( isalnum(var3) ) {
printf("var3 = |%c| is alphanumericn", var3 );
} else {
printf("var3 = |%c| is not alphanumericn", var3 ); }
return(0); }
20. isalpha() Function
Description
The C library function void isalpha(int c) checks if the passed
character is alphabet.
Declaration
int isalpha(int c);
Parameters
c − This is the character to be checked.
Return Value
This function returns non-zero value if c is a letter, else it returns 0.
21. Example:2#include <stdio.h>
#include <ctype.h>
int main () {
int var1 = 'a';
int var2 = '4';
int var3 = 't';
if( isalpha(var1) ) {
printf("var1 = |%c| is an alphabetn", var1 );
} else {
printf("var1 = |%c| is not an alphabetn", var1 );}
if( isalpha(var2) ) {
printf("var2 = |%c| is an alphabetn", var2 );
} else {
printf("var2 = |%c| is not an alphabetn", var2 );}
if( isalpha(var3) ) {
printf("var3 = |%c| is an alphabetn", var3 );
} else {
printf("var3 = |%c| is not an alphabetn", var3 );}
return(0); }
22. iscntrl() Function
Description
The C library function void iscntrl(int c) checks if the passed character
is a control character.
Declaration
int iscntrl(int c);
Parameters
c − This is the character to be checked.
Return Value
This function returns non-zero value if c is a control character, else it
returns 0.
23. Example:3#include <stdio.h>
#include <ctype.h>
int main ()
{
int i = 0, j = 0;
char str1[] = "We like to learn a about t programming";
char str2[] = "these tutorials n are nice";
/* Prints string till control character a */
while( !iscntrl(str1[i]) )
{
putchar(str1[i]);
i++;
}
/* Prints string till control character n */
while( !iscntrl(str2[j]) )
{
putchar(str2[j]);
j++;
}
return(0);
}
24. isdigit() Function
Description
The C library function void isdigit(int c) checks if the passed
character is a decimal digit character.
Decimal digits are (numbers) − 0 1 2 3 4 5 6 7 8 9.
Declaration
int isdigit(int c);
Parameters
c − This is the character to be checked.
Return Value
This function returns non-zero value if c is a digit, else it returns 0.
25. ispunct() Function
Description
The C library function int ispunct(int c) checks whether the passed
character is a punctuation character. A punctuation character is
any graphic character (as in isgraph) that is not alphanumeric (as
in isalnum).
Declaration
int ispunct(int c);
Parameters
c − This is the character to be checked.
Return Value
This function returns a non-zero value(true) if c is a punctuation
character else, zero (false).
26. isspace() Function
Description
The C library function int isspace(int c) checks whether the passed character is white-
space.Standard white-space characters are:
' ' (0x20) space (SPC)
't' (0x09) horizontal tab (TAB)
'n' (0x0a) newline (LF)
'v' (0x0b) vertical tab (VT)
'f' (0x0c) feed (FF)
'r' (0x0d) carriage return (CR)
Declaration
int isspace(int c);
Parameters
c − This is the character to be checked.
Return Value
This function returns a non-zero value(true) if c is a white-space character else, zero (false).
27. String Handling in C
String is a sequence of characters that is treated as a single data item and terminated by
null character '0'.
Remember that C language does not support strings as a data type.
A string is actually one-dimensional array of characters in C language.
These are often used to create meaningful and readable programs.
C language supports a large number of string handling functions that can be used to
carry out many of the string manipulations. These functions are packaged
in string.h library.
char name[12] = “DataScience"; // valid character array initialization
char name[12] = {‘d',‘a',‘t',‘a',‘s',‘c',‘i',’e’,’n’,’c’,’e’,'0'}; // valid initialization
char ch[3] = “data"; // Illegal
char str[4];
str = “data"; // Illegal
GO TO TOPICS
28. strlen()
o prototype: int strlen(char *);
o It calculates the length of the given string
strrev()
o prototype: char* strrev(char*);
o It reverses the given string
strlwr()
o prototype: char* strlwr(char*);
o It converts the given string into its corresponding lower case
strupr()
o prototype: char* strupr(char*);
o It converts the given string into its corresponding upper case
strcpy()
o prototype: char* strcpy(char*, char*);
o It copies the second string into first
29. strcat()
o prototype: char* strcat(char*, char*);
o It simply appends or concatenates the two strings.
strcmp()
o prototype: int strcmp(char*, char*);
o It compares two strings and return -1, 0 or 1, indicative values.
Return 0 if strings are identical.
Returns -1 if first string appears before the second string in the dictionary.
Returns 1 if first string appears after the second string in the dictionary.
OR
if Return value < 0 then it indicates str1 is less than str2.
if Return value > 0 then it indicates str2 is less than str1.
if Return value = 0 then it indicates str1 is equal to str2.
30. Example:1&2#include <stdio.h>
#include <string.h>
int main()
{
char str1[12] = "Hello";
char str2[12] = "Team";
char str3[12];
int len ;
/*copy str1 into str3 */
strcpy(str3, str1);
printf("strcpy(str3, str1) : %sn", str3 );
/*concatenates str1 and str2 */
strcat (str1, str2);
printf("strcat(str1, str2) : %sn", str1 );
/*total lenghth of str1 after concatenation */
len = strlen (str1);
printf("strlen(str1) : %dn", len );
return 0;
}
#include <stdio.h>
#include <string.h>
int main ()
{
char src[50], dest[50];
strcpy(src, "This is source");
strcpy(dest, "This is destination");
strcat(dest, src);
printf("Final destination string : |%s|", dest);
return(0);
}
31. Example:3
#include <stdio.h>
#include <string.h>
int main ()
{
char str1[15];
char str2[15];
int ret;
strcpy(str1, "abcdef");
strcpy(str2, "ABCDEF");
ret = strcmp(str1, str2);
if(ret < 0)
{
printf("str1 is less than str2");
}
else if(ret > 0)
{
printf("str2 is less than str1");
}
else
{
printf("str1 is equal to str2");
}
return(0);
}
32. 2.What does the following statement imply?
int arr[]={1,2,3,4,5,6,7,8,9,10};
A. Array uses only data type in its declaration
B. Array uses continuous memory addresses
C. Array is expandable
D. Array is derived data type
1. What is not true for an array?
A. The integer array does not contain any element.
B. The array contains 10 elements and the values are
natural numbers between 1 to 10.
C. The statement is not valid.
D. Array should have a dimension which is not given here.
GO TO TOPICS
33. 4. A matrix is a
A. We may use a loop to feed values into array.
B. An array can contain values belonging to different data type
categories.
C. An array can have only one dimension
D. An array cannot be copied to another variable of fundamental
data type
3. Which of the following statements is false?
A. Single dimensional array
B. Two dimensional array
C. Three dimensional array
D. Four dimensional array
34. 6. How many elements may be accommodated in
an array of dimension m and n? int arr[m][n]
A. Nested brackets are not allowed
B. There should not be any comma among between the numbers
C. There must be commas between the rows
D. The matrix is not having any dimensions mentioned for it.
5. What is wrong in this expression?
int mat[][]={{3,4},{7,8},{4,5},{20,10}}
A. Total number of elements that can be accommodated will
be m x n.
B. Total of m number of elements can be accommodated.
C. Total of n number of elements can be accommodated.
D. The declaration is defective
36. 9. Which function is used for checking if a
character is a control character?
A. isletter()
B. checkalpha()
C. isalpha()
D. checkletter()
8. Which function is used for checking if a character is
alphabet?
A. isspecial()
B. iscntrl()
C. isgraphic()
D. checkspl()
37. 11. Which function is used for checking if a character is a
punctuation?
A. isnum()
B. isnumber()
C. isdigit()
D. checkdigit()
10. Which function is used for checking if a character is a
digit?
A. ispunct()
B. ispnct()
C. isgraphic()
D. isdigit()
38. 13. A length of the String may be calculated with
one of the following function. Identify the same.
A. Array of Characters
B. Array of Characters terminated with a ‘0’ null character
C. Is an object
D. Same as characters
12. String ar
A. strlength()
B. strlen()
C. strln()
D. length()
39. 15. If you have to write a function for finding the length
of string. What will be the logic?
A. Joining two String
B. Merging two String
C. Cutting one string with another
D. None of the above
14. strcat() is used for
A. Read the character in an array and count them until you reach the and of the
array
B. Read the character in an array and count them until you encounter a ‘0’.
C. The dimension of the declared character is the length of the string
D. None of the Above