0% found this document useful (0 votes)
22 views11 pages

String

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views11 pages

String

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

PROGRAMMING IN C

Unit 2

Lecture-4
Unit-2 Syllabus
 Control structures: Decision statements; if and switch statement; Loop
control statements: while, for and do while loops, jump statements,
break, continue, goto statements.
 Arrays: Concepts, One dimensional array, declaration and initialization
of one dimensional arrays, two dimensional arrays, initialization and
accessing, multi dimensional arrays.
 Functions: User defined and built-in Functions, storage classes,
Parameter passing in functions, call by value, Passing arrays to functions:
idea of call by reference, Recursion.
 Strings: Arrays of characters, variable length character strings, inputting
character strings, character library functions, string handling functions.
In this Lecture

String :- Array of Characters


String Declaration and Initialisation
String Handling Function
Character Library Functions
String

It is an array of characters


Terminated with a null character i.e ' \0'
The difference between a character array and a
C string is that the string in C is terminated with a
unique character ‘\0’.
String Declaration in C

Declaring a string in C is as simple as declaring a


one-dimensional array.

char str[] = "Shivang";


String Initialisation
It is also similar as initalising an array
char str[8] = { 'S','h','I','v','a','n','g','\0'};
char str[] = { 'S','h','I','v','a','n','g','\0'};

Also it can be initalise as:-


char str[] = "Shivang";
char str[30] = "Shivang";
Write a Program
in which you take
user name input and
greet him
Gets and Puts

Scanf() is not capable of receiving multi-word strings , So


this problem is solved by using function gets().
Gets() is use with its counterpart puts
Puts() work as a replaemment for printf in case of strings.

Note :- Scanf() can also receive multi-word string using scanset

scanf("%[^\n]s", str);
Function Name Description

strlen(string_name) Returns the length of string name.

C Library strcpy(s1, s2)

strcmp(str1, str2)
Copies the contents of string s2 to string s1.

Compares the first string with the second string. If

<String.h>
strings are the same it returns 0.

Concat s1 string with s2 string and the result is stored


strcat(s1, s2)
in the first string.

strlwr() Converts string to lowercase.

strupr() Converts string to uppercase.

strstr(s1, s2) Find the first occurrence of s2 in s1.


More Library
Functions
Thank You

You might also like