Professional Documents
Culture Documents
Lab Report 10 Background Theory and Conclusion
Lab Report 10 Background Theory and Conclusion
Background Theory:
Introduction to string:
In C programming, a string is a sequence/array of characters terminated
with a null character \0 . For example: char c[] = "c string"; When the
compiler encounters a sequence of characters enclosed in the double
quotation marks, it appends a null character \0 at the end by default.
String handeling function: These functions are defined under the header
file string.h .These functions are designed for strings.
1) strlen(): This function basically counts the length of the string.
Eg: If char ch[50]= “Kathmandu” and int len=stelen(ch) then the
value of len will be 9.
2) strcat(): This function helps us to concatenate two strings.
Syntax: strcat(destination string,source string)
Eg:
#include <stdio.h>
#include <string.h>
int main() {
char str1[100] = "Hello ", str2[] = "everyone";
strcat(str1, str2);
puts(str1);
puts(str2);
return 0;
}
Output:
puts(str1);
puts(str2);
return 0;
}
Output:
1 if the first non-matching character in str1 is greater (in ASCII) than that
of str2 .
-1 if the first non-matching character in str1 is greater (in ASCII) than that
of str2 .
Two dimensional array in string: In c programming, we can actually
create two dimensional array of string. This will help us storing words in
different places. Application of it is we can extract word by word from a
sentence and perform the required task.
Here, during the lab report, i understood about string, how string is stored in
the variable, how string pre-defined function like strcmp, strlen works. Also I
learned how to sort strings in different orders.
Conclusion
Hence, Through Lab report, I got to clear my confusions regarding string and
debugged my mistakes. And from now, I am more confident on writing and
Understand C -Program.