100908/CO200F
BASICS OF C PROGRAMMING
Module III
MODULE III - SYLLABUS
Arrays and strings
Arrays Declaration and Initialization- processing an
array - 1-Dimensional Arrays, 2-Dimensional Arrays -
simple programs using single dimensional arrays –
linear search, bubble sort, simple programs using
multidimensional arrays – matrix operations.
String processing: reading and displaying
strings, In built String handling functions – gets,
puts, inbuilt string handling functions (strlen,
strcpy, strcat and strcmp), simple programs
covering strings
Dept of IT, RSET 2
COURSE OUTCOME
CO3: Write readable C programs with arrays, structure or
union for storing the data to be processed
Strings & String constants
• A string constant consists of a sequence of characters
enclosed in double quotes.
Examples: “Hi Rani!”
“1-Jan-2021”
“Welcome to C Programming”
Note: A string constant may consist of any combination
of digits, letters, escape sequences and spaces.
String variable
• Since a string is a sequence of characters, arrays
can be used to store and process strings.
• A string is an array of characters.
• A string variable is a one dimensional array of
characters that is capable of holding a string at a
time.
Run Time Initialization
E. Formatted Input
• The scanf() function is used to read the formatted data from the
standard input device (usually a keyboard).
• The scanf() function uses format specifier inside it indicating what sort
of data the function will read from the user.
& not required
How to read string with spaces using scanf() ?
• Read string with spaces by using "%[^\n]s" format specifier
• The format specifier "%[^\n]" tells the compiler to read the
characters until "\n" is not found.
• Example:
#include <stdio.h>
int main()
{
char str[20];
scanf("%[^\n]s", str);
printf("%s", str);
return 0;
}
String Handling Functions
21
22
23
24
Strcmp() function
29
30
31
32
THANK YOU