Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 /* malloc example: string generator*/ 00003 #include <stdio.h> 00004 #include <stdlib.h> 00005 00006 int main () 00007 { 00008 int i,n; 00009 char * buffer; 00010 00011 printf ("How long do you want the string? "); 00012 scanf ("%d", &i); 00013 00014 buffer = (char*) malloc (i+1); 00015 if (buffer==NULL) exit (1); 00016 00017 for (n=0; n<i; n++) 00018 buffer[n]=rand()%26+'a'; 00019 buffer[i]='\0'; 00020 00021 printf ("Random string: %s\n",buffer); 00022 free (buffer); 00023 00024 return 0; 00025 }
Generated on Sat Aug 6 2022 06:37:27 by
1.7.2