Mega Code Archive

 
Categories / C / Code Snippets
 

Use malloc to allocate memory

#include <stdio.h> #include <stdlib.h> int main(void) { char *j; j = malloc(80); if( !j ) { printf("Memory Allocation Failed"); exit(1); } printf("Enter a string: "); gets( j ); printf( j ); free( j ); return 0; }