#include <stdio.h>
#include <stdlib.h>
char getWord();
int main() {
char *word = getWord();
if(word != NULL){
printf("you entered:%s\n", word)
free(word);
}
return 0;
}
char getWord(){
//declaration + allocate memory
char *userWord = malloc(100);
if (userWord==NULL)
{
perror("Failed to allocate memory");
return NULL;
}
//if allocation was successful
printf("enter a message: ");
//read up to 99 char +1 for the null terminator)
scanf("%99s", userWord);
return userWord;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: