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 /* realloc example: rememb-o-matic */ 00003 #include <stdio.h> 00004 #include <stdlib.h> 00005 00006 int main () 00007 { 00008 int input,n; 00009 int count=0; 00010 int * numbers = NULL; 00011 int * more_numbers; 00012 00013 do { 00014 printf ("Enter an integer value (0 to end): "); 00015 scanf ("%d", &input); 00016 count++; 00017 00018 more_numbers = (int*) realloc (numbers, count * sizeof(int)); 00019 00020 if (more_numbers!=NULL) { 00021 numbers=more_numbers; 00022 numbers[count-1]=input; 00023 } 00024 else { 00025 free (numbers); 00026 puts ("Error (re)allocating memory"); 00027 exit (1); 00028 } 00029 } while (input!=0); 00030 00031 printf ("Numbers entered: "); 00032 for (n=0;n<count;n++) printf ("%d ",numbers[n]); 00033 free (numbers); 00034 00035 return 0; 00036 }
Generated on Tue Jul 19 2022 15:02:35 by
1.7.2