STRING
String is collection of Characters (or ) group of elements in
which symbols enclosed within quotation marks.
String is always declared as character arrays.
in other words character arrays are called as
STRINGS.
char name[5]={‘I’,’n’,’d’,’I’,’a’};

interpretation
Arrays whose elements are characters called as
string
Strings are always terminated with a NULL
character ('\0' or 0)
char a[]="hello\n";
/*size?*/
100
101
102
103
104
h
e
l
l
o

String Initialization
Initialization
char m[9] = “I like C”;
char m[ ]
= “I like C”;
char m[ ] = { ‘I’, ‘ ’, ‘l’, ‘i’, ‘k’, ‘e’, ‘ ’,’C’ };
char m[ ] ={
{ ‘I’ },{ ‘l’ },{
‘i’ },{ ‘k’ },{ ‘e’ },{‘u’ }
};

main()
{
char name1[9] = “I like C”;
char name2[9 ] ={
{ ‘I’ },{ ‘l’ },{
‘i’ },{ ‘k’ },{ ‘e’ },{ ‘u’ } };
char name3[9 ] = { ‘I’, ‘ ’, ‘l’, ‘i’, ‘k’, ‘e’, ‘ ’,’c’,’\0’ };
clrscr();
printf(“name1=%s”,name1);
printf(“name1=%s”,name2);
printf(“name1=%s”,name3);
}

Print the elements of char
array
main()
{
char str[15]=“have a nice day”;
int i=0;
while(i<=15)
{
printf(“%c”,str[i]);
i++;
}
}

Print the elements of char
array
main()
{
char str[ ]=“have a nice day”;
int i=0;
while( str[i]!=‘\0’)
{
printf(“%c”,str[i]);
i++;
}
}

Standard string functions
Strlen :-determines length of string
Strcpy :-copies a string from source to destination
Strncpy:-copies char of string to another string upto
specific length
Strcmp:-compare char of 2 strings
Stricmp:-compare 2 strings
Strncmp:-compare char of 2 strings upto specific length
Strnicmp:-compare char of 2 strings upto specific
length .Ignore case.

Strlen function
It counts the number of characters in a given
string.


You've reached the end of your free preview.
Want to read all 29 pages?
- Fall '19
- Pointer, ASCII, char name