// Basic Strings Revision // A string in C is an array of char which ends in a '/0' // The standard library which has a lot of useful string functions is // You can read a string from terminal by using fgets() function // Eg. string[] = "hello" is: // string[0] = 'h' // string[1] = 'e' // string[2] = '\0' // string[3] = 'l' // string[4] = '\0' // string[5] = '\n' // string[6] = '\0' // #include #define MAX 100 int main (void) { char string_array[MAX]; printf("Enter a word: "); //read the string from terminal into string_array[] using fgets() fgets(string_array, MAX, stdin); // Let's say the word is: hello // I can print out the first character: printf("The first character of the word is: %c\n", string_array[0]); //I can change it up: string_array[4] = 'g'; //This means the word is now "hellg" printf("%s\n", string_array); //I can truncate it to my heart's content: string_array[4] = '\0'; //This means the word is now "hell" printf("%s\n", string_array); string_array[2] = '\0'; printf("%s\n", string_array); return 0; }