Thefaceofbo

Matrix

Nov 19th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct {
  5. float *M;
  6. int size;
  7. int cols;
  8. int rows;
  9. } matrix2;
  10.  
  11. float getAngle(int);
  12. matrix2 copyMatrix2(matrix2 *);
  13. int find(char *, char *);
  14.  
  15. int main(void) {
  16. matrix2 *x;
  17. matrix2 *y;
  18. x = (matrix2 *)malloc(sizeof(matrix2));
  19. x->cols = 2;
  20. x->rows = 2;
  21. x->size = x->rows * x->cols;
  22. x->M = (float *)malloc(sizeof(float)*x->size);
  23. x->M[0] = 5;
  24. *y = copyMatrix2(x);
  25. printf("%f\n", y->M[0]);
  26. return 0;
  27. }
  28.  
  29. float getAngle(int n) {
  30. return 360/n;
  31. }
  32.  
  33. int find(char *, char *) {
  34. /* Doing this in C Takes 4 arguments and a mess most likely */
  35. return -1;
  36. }
  37.  
  38. matrix2 copyMatrix2(matrix2 *m) {
  39. matrix2 *error = NULL;
  40. matrix2 *copy;
  41. float *mCopy;
  42. int i = 0;
  43. int length = m->rows*m->cols;
  44. if (m == NULL) {
  45. return *error;
  46. }
  47. copy = (matrix2 *)malloc(sizeof(matrix2));
  48. mCopy = (float *)malloc(sizeof(float)*length);
  49. copy->rows = m->rows;
  50. copy->cols = m->cols;
  51. for (i=0; i<length; i++) {
  52. mCopy[i] = (m->M)[i];
  53. }
  54. copy->M = mCopy;
  55. return *copy;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment