Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2014
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. int main(int argc, char const *argv[]){
  2. int *array ;
  3. foo(array) ;
  4. /* Rest of the code */
  5. }
  6.  
  7. int foo(int *array){
  8. // I know I am missing some *malloc not working* if's
  9. int *temp , j = 0 , i;
  10. array = malloc(sizeof(int)) ;
  11. if (array){
  12. for (i=0 ; i < 10 ; i++){
  13. array[j] = i*i ;
  14. temp = realloc( array , (++j+1)*sizeof(int) ) ;
  15. if (temp != NULL ) {
  16. array = temp ;
  17. }
  18. }
  19. }
  20. return j
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement