fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct vec_int{
  5. int allocate_size;
  6. int size; // used size
  7. int* val;
  8. };
  9. void valloc(struct vec_int* p_vec, int size){
  10. p_vec->allocate_size = size;
  11. p_vec->size = size;
  12. p_vec->val = (int*)malloc(size*sizeof(int));
  13. return p_vec;
  14. }
  15.  
  16. struct vvec_int{
  17. int allocate_size;
  18. int size; // used size
  19. struct vec_int* val;
  20. };
  21. void vvalloc(struct vvec_int* p_vvec, int rows, int cols){
  22. p_vvec->allocate_size=rows;
  23. p_vvec->size=rows;
  24. p_vvec->val = (struct vec_int*)malloc(rows*sizeof(struct vec_int));
  25. for(int i=0; i<rows; i++){
  26. valloc(&p_vvec->val[i], cols);
  27. }
  28. return p_vvec;
  29. }
  30.  
  31. void vvprint(const struct vvec_int* p_vvec){
  32. for(int p=0; p<p_vvec->size; p++){
  33. printf("[ ");
  34. for(int q=0; q<p_vvec->val[p].size; q++){
  35. printf("%d ", p_vvec->val[p].val[q]);
  36. }
  37. printf("]\n");
  38. }
  39. }
  40.  
  41. int main(){
  42. struct vvec_int vvec;
  43. vvalloc(&vvec, 3, 3);
  44.  
  45. int i=0;
  46. for(int p=0; p<vvec.size; p++){
  47. for(int q=0; q<vvec.val[p].size; q++){
  48. vvec.val[p].val[q] = i++;
  49. }
  50. }
  51.  
  52. vvprint(&vvec);
  53. return 0;
  54. }
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
[ 0 1 2 ]
[ 3 4 5 ]
[ 6 7 8 ]