#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *readStr(void);

int main() {
    char *strPtr;
    strPtr = readStr();
    if(strPtr != NULL) {
        printf("message you entered: %s\n", strPtr);
        free(strPtr);
        strPtr = NULL;
    }
    return 0;
}

char *readStr(void){
    char *sPtr = (char*)malloc(sizeof(char)*100);
    if(sPtr == NULL){
        printf("mem allc failed");
        return NULL;
    }
    printf("enter a message: ");
    fgets(sPtr, 100, stdin);
    //remove newline, if any.
    size_t len = strlen(sPtr);
        if(len > 0 && sPtr[len - 1] == '\n')
            sPtr[len - 1] = '\0';
    return sPtr;
 }

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: