A1438377233_17451_10_2017_STRINGS new.ppt - STRING String is collection of Characters(or group of elements in which symbols enclosed within quotation

A1438377233_17451_10_2017_STRINGS new.ppt - STRING String...

This preview shows page 1 - 9 out of 29 pages.

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’};
Image of page 1
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
Image of page 2
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’ } };
Image of page 3
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); }
Image of page 4
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++; } }
Image of page 5
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++; } }
Image of page 6
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.
Image of page 7
Strlen function It counts the number of characters in a given string.
Image of page 8
Image of page 9

You've reached the end of your free preview.

Want to read all 29 pages?

  • Fall '19
  • Pointer, ASCII, char name

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture