TECHNOLOGY,
CHENNAI.
18CSS101J – Programming for ProblemSolving
Unit III
18CSS101J –Programming for Problem Solving
Unit III
, SRM INSTITUTE OF SCIENCE AND
TECHNOLOGY,
CHENNAI.
Unit III: Content
String Basics – String Declaration and Initialization – String Functions:
gets(), puts(), getchar(), putchar(), printf() - String Functions: atoi,
strlen, strcat strcmp – String Functions: sprintf, sscanf, strrev, strcpy,
strstr, strtok – Arithmetic characters on strings.
,STRING BASICS
● Strings in C are represented by arrays of characters.
● String is nothing but the collection of the individual array elements
or characters stored at contiguous memory locations
i) Character array – 'P','P','S'
ii) Double quotes - “PPS" is a example of String.
− If string contains the double quote as part of string then we can
use escape character to keep double quote as a part of string.
− “PP\S" is a example of String
, iii) Null Character
− The end of the string is marked with a special character, the null
character, which is a character all of whose bits are zero i.e., a
NULL.
− String always Terminated with NULL Character (‘/0′)
char name[10] = {'P','P','S','\0'}
● NULL Character is having ASCII value 0
● ASCII Value of '\0' = 0
● As String is nothing but an array , so it is Possible to
Access Individual Character
name[10] = "PPS";
− It is possible to access individual character
name[0] = 'P';
name[1] = 'P';
name[2] = 'S';
name[3] = '\0';