HI I am currently in a college level programming class studying C, I've been enjoying coding and have seriously thought about it as a career... up until now.

here is the link to the homework assignment if anyone is interested:

http://www.engineering.uiowa.edu/~cie/Homework/hw02.htm

In short I have to create 2 matricies using single string arrays, transpose them, add and subtract them.

I don't fully understand arrays and pointers but this is what I have, I'm sorry it's so long.

#include <stdio.h>
#define SIZE 100


void readarraya(float array[SIZE],int row, int col);
void printarray(float array[],int row, int col);
void transpose(float array[], int row, int col);
void readarrayb(float array[SIZE],int row, int col);
void matrixadd(float array[],int row,int col);

int main(){

int *a[SIZE];
int *b[SIZE];
int *c[SIZE];
int *row;
int *col;

readarraya(&a,&row,&col);
printarray(&a,&row,&col);
transpose(&a,&row,&col);
readarrayb(&b,&row,&col);
printarray(&b,&row,&col);
transpose(&b,&row,&col);





return 0;
}

void readarraya(float array[SIZE], int row, int col){
	int i=0;

	while (i==0);{
	printf("How many rows would you like in the array?:");
			scanf("%d",&row);
	printf("How many columns would you like the in the array?:");
	scanf("%d",&col);

		if (row<0){
			printf("Your rows need to be positive, please try again.");
		}
		else if (col<0){
			printf("Your columns need to be positive, please try again.");
		}
		else if((col*row)>SIZE){
			printf("The Size of the array is too big, try again.");
		}
		else
			i=1;
	}

	int j=0;

	printf("Enter the values of the array:");

	for(j=0;j<SIZE;i++){

		scanf("%f,",array[j]);

	}

}

void printarray(float array[],int row, int col){

	int i=0;
	int j=0;
	int k=0;

	for (j=0;j<row;j++){
		for(i=0;i<col;i++){
			k=i*col+j;
			printf("%f",&array[k]);

		}
		printf("\n");
	}



}

void transpose(float array[],int row, int col){



}


void readarrayb(float array[SIZE], int row, int col){
	int i=0;

	while (i==0);{
	printf("How many rows would you like in the array?:");
			scanf("%d",&row);
	printf("How many columns would you like the in the array?:");
	scanf("%d",&col);

		if (row<0){
			printf("Your rows need to be positive, please try again.");
		}
		else if (col<0){
			printf("Your columns need to be positive, please try again.");
		}
		else if((col*row)>SIZE){
			printf("The Size of the array is too big, try again.");
		}
		else
			i=1;
	}

	int j=0;

	printf("Enter the values of the array:");

	for(j=0;j<SIZE;i++){

		scanf("%f,",array[j]);

	}

}


void matrixadd(float array[],int row,int col){


}

Yes, it's bad but my question is: am I prompting the user for the matrix values in the right way?

printf("Enter the values of the array:");

	for(j=0;j<SIZE;i++){

		scanf("%f,",array[j]);

How would i convert the array to a matrix? i'm guessing using the row and col integers but i'm stumped

The transpose, add and subtract functions are way over my head. IF anyone could help me and tell me what i'm doing wrong so I can learn from my mistakes I would really appreciate it

I would suggest if(row < 1) and if(col < 1), rather than < 0. Our arrays start with zero, but that is the first row, so the array has to have at least 1 row, and 1 column, also.

Think about that data entry loop. If I say I want 2 rows with 5 columns each, why would you want a loop asking for values up to SIZE (100)?

Before you enter any values, you need to malloc() memory for the array!

In your print function, you need to remove the ampersand '&' from &array[k], and in the scanf()'s you need to add the ampersand in front of array[j]

An array is a matrix - if you mean from a 1D array to a 2D matrix (with rows and columns), that is done when you malloc the memory.

In main, row and col should be int's, not int pointers, unless your assignment requires it. When other functions need to modify the row or col number in main, then they should be passed the address of row or col, and receive it as a pointer, in the called function.

This article has been dead for over six months. Start a new discussion instead.