Strings Theory.pdf
Document Details
Uploaded by Deleted User
Full Transcript
Strings By Sashika Kumarasinghe Learning Objectives At the end of the lecture, you should be able to, Understand Strings Use gets() and puts() Use standard string functions IN 1101 Programming Fundamentals What are Strings? Group of characters can...
Strings By Sashika Kumarasinghe Learning Objectives At the end of the lecture, you should be able to, Understand Strings Use gets() and puts() Use standard string functions IN 1101 Programming Fundamentals What are Strings? Group of characters can be stored in a character array. Many languages internally treat ‘strings’ as character arrays. The array of characters are arranged one after another in memory as successive elements. A string is always terminated by a null character (i.e. slash zero \0). Example: char name[ ] = { 'H', 'A', 'E', 'S', 'L', 'E', 'R', '\0' } ; Note : ‘\0’ is not necessary in some declarations. e.g.: char name[ ] = "HAESLER" ; The %s used in printf( ) is a format specification for printing out a string. IN 1101 Programming Fundamentals Example What is the output of this program? # include int main( ) Rewrite the program without using { length of the program to get the char name[ ] = "Klinsman" ; same output int i = 0 ; while ( i