![](/media/cache/profiles/perfil.jpeg.50x50_q85.jpg)
malloc, descripcion y ejemplo
Revision 0:984f552374ff, committed 2012-04-03
- Comitter:
- sherckuith
- Date:
- Tue Apr 03 21:01:54 2012 +0000
- Commit message:
- malloc, descripcion y ejemplo
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Apr 03 21:01:54 2012 +0000 @@ -0,0 +1,25 @@ +#include "mbed.h" +/* malloc example: string generator*/ +#include <stdio.h> +#include <stdlib.h> + +int main () +{ + int i,n; + char * buffer; + + printf ("How long do you want the string? "); + scanf ("%d", &i); + + buffer = (char*) malloc (i+1); + if (buffer==NULL) exit (1); + + for (n=0; n<i; n++) + buffer[n]=rand()%26+'a'; + buffer[i]='\0'; + + printf ("Random string: %s\n",buffer); + free (buffer); + + return 0; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Apr 03 21:01:54 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/737756e0b479