/*
write a prog: user enters input(string), prog will print the input
-use malloc
-user can enter the limit of the string, when entering
-use this limit when invoking malloc
-creat a char pointer(not array)
*/

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

int getLimit(void);
char *getPtr(int size);

int main()
{
    int limit = getLimit();
    char *ptr = getPtr(limit);
    printf("%s", ptr);
}

int getLimit(void){
    int limit = 0;
    printf("enter the limit: ");
    scanf("%d", &limit);
    scanf("\n");
    return limit;
}

char *getPtr(int size){
    char *ptr = (char*)malloc(size*sizeof(char));
    printf("enter the message: ");
    fgets(ptr, size, stdin);
    return ptr;
}

Embed on website

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