Skip to content

Instantly share code, notes, and snippets.

@irrationnelle
Created October 20, 2015 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save irrationnelle/320645af276131570ba3 to your computer and use it in GitHub Desktop.
Save irrationnelle/320645af276131570ba3 to your computer and use it in GitHub Desktop.
Using malloc function to input each name infos in dynamic allocation
#include <stdio.h>
#include <stdlib.h>
char * ReadUserName(void)
{
char * name = (char *)malloc(sizeof(char)*30);
printf("What's your name?: ");
gets(name);
return name;
}
int main(void)
{
char * name1;
char * name2;
name1=ReadUserName();
printf("%s \n", name1);
name2=ReadUserName();
printf("%s \n", name2);
printf("%s \n", name1);
printf("%s \n", name2);
free(name1);
free(name2);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment