Using malloc() to create and read strings from standard input - C Memory

C examples for Memory:malloc

Description

Using malloc() to create and read strings from standard input

Demo Code

#include <stdio.h> 
#include <stdlib.h> 
int main()//  w  w w . ja  v a  2  s .c  o  m
{ 
   char *name; 
   name = (char *) malloc(80*sizeof(char)); 
   if ( name != NULL ) { 
      printf("\nEnter your name: "); 
      gets_s(name,80); 
      printf("\nHi %s\n", name); 
   }
}

Result


Related Tutorials