Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct {
- float *M;
- int size;
- int cols;
- int rows;
- } matrix2;
- float getAngle(int);
- matrix2 copyMatrix2(matrix2 *);
- int find(char *, char *);
- int main(void) {
- matrix2 *x;
- matrix2 *y;
- x = (matrix2 *)malloc(sizeof(matrix2));
- x->cols = 2;
- x->rows = 2;
- x->size = x->rows * x->cols;
- x->M = (float *)malloc(sizeof(float)*x->size);
- x->M[0] = 5;
- *y = copyMatrix2(x);
- printf("%f\n", y->M[0]);
- return 0;
- }
- float getAngle(int n) {
- return 360/n;
- }
- int find(char *, char *) {
- /* Doing this in C Takes 4 arguments and a mess most likely */
- return -1;
- }
- matrix2 copyMatrix2(matrix2 *m) {
- matrix2 *error = NULL;
- matrix2 *copy;
- float *mCopy;
- int i = 0;
- int length = m->rows*m->cols;
- if (m == NULL) {
- return *error;
- }
- copy = (matrix2 *)malloc(sizeof(matrix2));
- mCopy = (float *)malloc(sizeof(float)*length);
- copy->rows = m->rows;
- copy->cols = m->cols;
- for (i=0; i<length; i++) {
- mCopy[i] = (m->M)[i];
- }
- copy->M = mCopy;
- return *copy;
- }
Advertisement
Add Comment
Please, Sign In to add comment