Videos
As there are a lot of string manipulation functions, what are note-worthy?
Your system probably uses ASCII. In ASCII, the codepoints of lowercase characters and uppercase characters are sequential.
So we can just do:
void to_upper(char *message) {
while (*message) {
if (*message >= 'a' && *message <= 'z')
*message = *message - 'a' + 'A';
message++;
}
}
Other character encodings can become much more complicated. For example, EBCDIC doesn't have contiguous characters. And UTF-8 introduces a world of problems because of the numerous languages that you need to support.
You can just check if the character is within the range of characters, say between 'a' and 'z' and just add or subtract 32, which is the difference between the ascii value of capital and lower letters. See the ascii table here: http://www.asciitable.com/
There is nothing like string in C
The best you can do declare the string is like this:
char greeting[] = "Hello";
or like this:
char greeting[6] = {'H', 'e', 'l', 'l', 'o', '\0'};
Check out this tutorial.
The string in C programming language is actually a one-dimensional array of characters which is terminated by a null character '\0'. Thus a null-terminated string contains the characters that comprise the string followed by a null.
There is no string in C. Essentially, in C string is nothing but an array of chars.
You can use char* which is a pointer to a char variable. I don't know how much do you know about C pointers but when you do something like
int a[10]
which is an array declaration a pointer to integers is saved in as variable a. So it's the same in chars if you use char* as a pointer to a char you have a char array with no default size. But be careful when working with pointers you can face so many run time errors so be careful when writing codes involving pointers.