Strings are actually one-dimensional array of characters terminated by a null character '\0'. Thus a null-terminated string contains the characters that comprise the string followed by a null.
The following declaration and initialization create a string consisting of the word "Hello". To hold the null character at the end of the array, the size of the character array containing the string is one more than the number of characters in the word "Hello."
The following declaration and initialization create a string consisting of the word "Hello". To hold the null character at the end of the array, the size of the character array containing the string is one more than the number of characters in the word "Hello."
char greeting[6] = {'H', 'e', 'l', 'l', 'o', '\0'};If you follow the rule of array initialization then you can write the above statement as follows −
char greeting[] = "Hello";In this section, we shall learn how to work with string C programming language. We have divided the examples in multiple sub-sections to have a better understanding of what we are doing −
Basic Programs
These programs made specially to understand the basics of strings in C. These program deals with string as an array of characters.- Program to print a string in C
- Program to print a string character by character in C
- Program to find string length without function in C
- Program to count character occurrent in C
- Program to count vowels occurrent in C
- Program to sort string characters in C
Multi-string Programs
These programs has more than one string variables. These should give you an insight of how to work with multiple string variables in C programming language −- Program to copy string in C
- Program to reverse string in C
- Program to search strings in C
- Program to swap strings in C
- Program to compare two strings in C
- Program to concatenate two strings in C
- String Anagram program in in C
No comments:
Post a Comment