string text line

#include <stdio.h>
#include <string.h>

int main() {
    char text[100];  // Declare a character array named 'text' with a size of 100.

    printf("Enter a text line: ");  // Display a prompt to enter a text line.
    fgets(text, sizeof(text), stdin);  // Read a line of text from the standard input (keyboard) and store it in the 'text' array.

    // Remove the newline character at the end of the input, if present.
    if (text[strlen(text) - 1] == '\n') {
        text[strlen(text) - 1] = '\0';
    }

    printf("Entered text: %s\n", text);  // Display the entered text.

    // Calculate and display the length of the entered text.
    printf("Length of the text: %lu\n", strlen(text));

    // Tokenize the text into words and display each word.
    char *token = strtok(text, " ");
    printf("Words in the text:\n");
    while (token != NULL) {
        printf("%s\n", token);
        token = strtok(NULL, " ");
    }

    return 0;  // Return 0 to indicate successful execution.
}